我正试图登录到website。随着下面的一段代码:Python请求ConnectionError
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))
这是登录到网站的形式。
<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>
好吧,当我运行代码,我得到这个错误:
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',))
我怎样才能解决这个问题?我可以在浏览器中登录,但无法通过Python代码登录。
你可以用'mechanize'或'selenium' – AlexDotis
尝试我删除了答案,因为它太大与请求一起工作。最好切换到机械化 –
好吧,但我认为机械化仅适用于python 2.我正在使用python 3.我应该尝试使用硒吗? – cactus