Reputation: 50
I'm trying to login to this website. With the following piece of code:
import requests
values = {'password': 'somepass', 'username': 'someusername'}
login_url = "http://voobly.com/login"
session_requests = requests.session()
r = session_requests.post(login_url, data=values,
headers=dict(referer=login_url))
And this is the form to login into the website.
<form action="/login/auth" method="post">
<label for="username">Username: </label>
<input type="text" name="username" id="username" class="inputfield" value="">
<label for="password">Password: </label>
<input type="password" name="password" id="password" class="inputfield">
<input type="submit" value="Login" class="login-button">
</form>
Well, when I run the code I get this error:
HTTPConnectionPool(host='www.voobly.com', port=80): Max retries exceeded with url: /login
(Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f7cca037be0>:
Failed to establish a new connection: [Errno -2] Name or service not known',))
How I can solve this? I can login in the browser but I can't login throught python code.
Upvotes: 0
Views: 808
Reputation: 2391
You are sending POST request to a wrong URL, it should be http://www.voobly.com/login/auth
:
import requests
values = {'password': 'somepass', 'username': 'someusername'}
login_url = "http://www.voobly.com/login/auth"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64)',
... # more...
'Referer': 'http://www.voobly.com/login'}
session_requests = requests.session()
r = session_requests.post(login_url, data=values,
headers=headers)
Upvotes: 1