Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 error with requests
#1
Trying to login using requests but I'm getting html returned that appears to be an error page.

Python:
import requests

with requests.Session() as c:
    url = "http://10.10.....html"
    user_name = input("Enter your username: ")
    password = input("Enter your password: ")

    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'}

    c.get(url, headers = headers)
    login_data = dict(txt_inptUserId = user_name, txt_password = password, headers = headers)
    c.post(url, data = login_data)

    page = c.get(url)
    print(page.content)
HTML-Error?:
Quote:C:\Users\user\Desktop\requests>test.py
Enter your username number: xyz
Enter your password: xyz
b'<html>\r\n <head>\r\n <title>App</title>\r\n </head>\r\n <frameset na
me="jacadaframeset" frameborder="0" framespacing="0" rows="100%,*">\r\n <fram
e name="jacadaframe" frameborder="0" marginheight="0" marginwidth="0" src="/Xhtm
l?JacadaApplicationName=App"/>\r\n </frameset>\r\n <noframes>\r\n <p>You
r browser doesn\'t support frames!<p>\r\n window.location.href="/Xhtml?Jacada
ApplicationName=App";\r\n </noframes>\r\n</html>\r\n'
Quote
#2
They problem is likely in your log in method,then the return is correct.
It's not possible to help without seeing the page,there is a lot of different method log-in method that web-pages use.
You have to inspect web-page to see what's happens when log in,eg use Chrome/FireFox developer tool.
Have posted this before,example how to log in into this forum see that i need to find params used.
I use Session() so it's persist against requests and cookies.
import requests
from bs4 import BeautifulSoup

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}

params = {
    "username": "your_username",
    "password": "xxxxxxx",
    "remember": "yes",
    "submit": "Login",
    "action": "do_login",
}

with requests.Session() as s:
    s.post('https://python-forum.io/member.php?action=login', headers=headers, params=params)
    # logged in! session cookies saved for future requests
    response = s.get('https://python-forum.io/index.php')
    # cookies sent automatically!
    soup = BeautifulSoup(response.content, 'lxml')
    welcome = soup.find('span', class_="welcome").text
    print(welcome)
Output:
Welcome back, snippsat. You last visited: Today, 05:44 PM Log Out
Quote
#3
Here's a rundown of the tags/elements:
<input id="inptUserId" maxlength="8"
	name="txt_inptUserId" onkeyup="autoSkipNN(event.which,this);" onfocus="saveFocusedControl(&quot;inptUserId&quot;);" style="background-color:Window;font-size:11px;height:19px;width:67px;line-height:11px;left:275px;padding-bottom:0;font-family:Arial;border-width:2px;position:absolute;border-style:inset;top:101px;color:000000;padding-top:0;" tabindex="26"
	title="" type="text" value="">
<input id="password" maxlength="8"
	name="txt_password" onkeyup="autoSkipNN(event.which,this);" onfocus="saveFocusedControl(&quot;password&quot;);" style="background-color:Window;font-size:11px;height:19px;width:67px;line-height:11px;left:445px;padding-bottom:0;font-family:Arial;border-width:2px;position:absolute;border-style:inset;top:101px;color:000000;padding-top:0;" tabindex="28"
	title="" type="password" value="">
Then I need to click this button after logging in:

<input alt="Enter" id="btnOK"
	name="btn_btnOK" onfocus="saveFocusedControl(&quot;btnOK&quot;);" style="font-family: Arial; font-size: 12px; font-weight: Bold; position: absolute; left: 19px; top: 292px; width: 49px; height: 23px; color: #ffffcc; background-color: transparent; border-width: 0px; text-align:left;padding-left:0px;padding-right: -5px;cursor: pointer; padding-left:0px;padding-right:0px;" tabindex="-1"
	title="" type="submit" value="Enter">
(May-07-2019, 04:34 PM)snippsat Wrote: I use Session() so it's persist against requests and cookies.
What is Session()? Is that a function/method of requests or another module itself? Thanks.

Also, does this help?
Form Data
Output:
Applname: App Formname: SIGNON sessionId: 180... sequenceNumber: 2 focusedControl: NewPassword keepAliveURL: /KeepAlive? keepAliveInterval: 60000 clientDebugLevel: 0 defaultbtn_btnOK: activate default default_btnOK: 1 txt_txtActiveHelpHtml: txt_txtPrevFocus: txt_txtRecordFlag: txt_txtMacros: txt_txtFieldValue: txt_txtMugShots: txt_txtSavedHelpValue: txt_txtFavorites: txt_txtTableLinkStyle: -1 txt_txtKeyBoardSupport: txt_inptUserId: myUserName txt_password: abc123 txt_NewPassword:
Quote
#4
I fixed code tags in your post,look at BBCode
rudolphyaber Wrote:What is Session()? Is that a function/method of requests or another module itself? Thanks.
Session Objects when you use a browser the states eg cookies is kept.
Doing it outside of browser need to keep state persist,when eg doing request(get, post).
You are using Session in your post so that's okay.

rudolphyaber Wrote:Also, does this help?
Form Data
Is this form data of html on site?
You have to look in Network tab of Chrome/FireFox developer tool,when you try to log in browser.
Then Form Data that get send can be found.
Quote
#5
(May-08-2019, 08:48 AM)snippsat Wrote: Is this form data of html on site?
You have to look in Network tab of Chrome/FireFox developer tool,when you try to log in browser.
Then Form Data that get send can be found.

Yes it got this from under the Network tab of Chrome's developer tools.
Quote
#6
Not sure without looking is all of that is send as form data.
Can try this, if fail try to send all that you posted.
params = {
txt_txtActiveHelpHtml: '',
txt_txtPrevFocus:  '',
txt_txtRecordFlag: '',
txt_txtMacros: '',
txt_txtFieldValue: '',
txt_txtMugShots: '',
txt_txtSavedHelpValue: '',
txt_txtFavorites:  '',
txt_txtTableLinkStyle: -1,
txt_txtKeyBoardSupport: '',
txt_inptUserId: myUserName ,
txt_password: abc123 ,
txt_NewPassword:  '',
}
Quote
#7
(May-11-2019, 08:36 AM)snippsat Wrote: Not sure without looking is all of that is send as form data.
Can try this, if fail try to send all that you posted.
All that the user enters into the form in the browser is the username and password. I also have two screenshots but the image button on here only lets me use a url, I don't see a way to upload the images.

I added this code:
    params = {  txt_txtActiveHelpHtml: '',
                txt_txtPrevFocus:  '',
                txt_txtRecordFlag: '',
                txt_txtMacros: '',
                txt_txtFieldValue: '',
                txt_txtMugShots: '',
                txt_txtSavedHelpValue: '',
                txt_txtFavorites:  '',
                txt_txtTableLinkStyle: -1,
                txt_txtKeyBoardSupport: '',
                txt_inptUserId: {user_name},
                txt_password: {password},
                txt_NewPassword:  '',
and this is what I got:
params = { txt_txtActiveHelpHtml: '',
NameError: name 'txt_txtActiveHelpHtml' is not defined


It actually give this error for all of them. But these are the variable that chrome shows for form data for logging in.
Quote
#8
All should be string,so like this.
params = {
"txt_txtActiveHelpHtml": '',
"txt_txtPrevFocus":  '',
"txt_txtRecordFlag": '',
"txt_txtMacros": '',
"txt_txtFieldValue": '',
"txt_txtMugShots": '',
"txt_txtSavedHelpValue": '',
"txt_txtFavorites":  '',
"txt_txtTableLinkStyle": -1,
"txt_txtKeyBoardSupport": '',
"txt_inptUserId": 'myUserName',
"txt_password": 'abc123',
"txt_NewPassword":  '',
}
Quote
#9
(May-14-2019, 07:53 PM)snippsat Wrote: All should be string,so like this.
The returned html has the correct title for the page between the <title> tags and so does the ApplicationName but still don't think I'm getting a good return, this is what I'm getting:
[icode]
b'<html>\r\n
<head>\r\n
<title>APP</title>\r\n
</head>\r\n
<frameset name="jacadaframeset" frameborder="0" framespacing="0" rows="100%,*">\r\n
<frame name="jacadaframe" frameborder="0" marginheight="0" marginwidth="0" src="/Xhtml?JacadaApplicationName=APP"/>\r\n
</frameset>\r\n <noframes>\r\n
<p>Your browser doesn\'t support frames!<p>\r\n window.location.href="/Xhtml?JacadaApplicationName=APP";\r\n
</noframes>\r\n</html>\r\n'
[/icode]
Quote
#10
(May-14-2019, 07:53 PM)snippsat Wrote: All should be string,so like this.
And I did make that change.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Cherrypy - no response to requests kryszen2 6 159 May-19-2019, 09:57 AM
Last Post: kryszen2
  requests - handling exceptions Truman 2 347 Nov-13-2018, 11:54 PM
Last Post: Truman
  flask requests display data from api on webpage with javacript pascale 0 366 Oct-25-2018, 08:30 PM
Last Post: pascale
  Error in requests.post debanilroy 3 717 Sep-18-2018, 06:15 PM
Last Post: snippsat
  help about requests download ggbaby 1 312 Sep-18-2018, 03:44 AM
Last Post: wavic
  Requests login failure test 10 1,146 Sep-13-2018, 08:48 AM
Last Post: test
  Inserting multiple cookies using python requests freshtomatoes 0 676 Aug-16-2018, 09:25 PM
Last Post: freshtomatoes
  Logging into a website with requests HiImNew 3 808 Jul-06-2018, 06:00 AM
Last Post: HiImNew
  working with lxml and requests gentoobob 23 1,851 Apr-19-2018, 06:54 PM
Last Post: gentoobob
  An Error in Requests Module pratheep 3 2,634 Feb-06-2018, 05:17 PM
Last Post: pratheep

Forum Jump:


Users browsing this thread: 1 Guest(s)