I'm trying to make a fairly basic requests script which signs into a website, however I'm running into a problem; the website requires the 'pass' key, however whenever I try to use this python throws an error saying invalid syntax. Here's my code:
import requests
with requests.Session() as c:
url = 'www.a_url.com'
USERNAME = 'a username'
PASSWORD = 'a password'
c.get(url)
login_data = dict(user=USERNAME, pass=PASSWORD, jsok='1', dologin='Login')
c.post(url, data=login_data, headers={"Referer": 'www.a_referer.com'})
page = c.get('www.a_page.com')
print(page.content)
output = open('test.html','w')
output.write(str(page.content))
And the error I'm given is:
login_data = dict(user=USERNAME, pass=PASSWORD, jsok='1', dologin='Login')
^
SyntaxError: invalid syntax
Any idea how I can force python to ignore the 'pass' and just use it as the dict key?
Since pass is a keyword, it can't be used as an identifier. You'll need to use a dict-literal for this:
login_data = {
'user': USERNAME,
'pass': PASSWORD,
'jsok': '1',
'dologin': 'Login',
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With