我正試圖登錄到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