【发布时间】:2017-03-15 17:42:38
【问题描述】:
我正在尝试通过 Python 登录网站。我有以下代码:
import sys
sys.path.append('ClientCookie-1.3.0')
import ClientCookie
sys.path.append('ClientForm-0.2.10')
import ClientForm
cookieJar = ClientCookie.CookieJar()
opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(cookieJar))
opener.addheaders = [("User-agent","Mozilla/5.0 (compatible)")]
ClientCookie.install_opener(opener)
fp = ClientCookie.urlopen("login_page_url")
forms = ClientForm.ParseResponse(fp)
fp.close()
# print forms on this page
for form in forms:
print("***************************")
print(form)
form = forms[2]
form["username"] = "some_username"
form["password"] = "some_password"
fp = ClientCookie.urlopen(form.click())
fp.close()
fp = ClientCookie.urlopen("some_url_for_authorized_users_only")
html = fp.read()
fp.close();
print(html.decode('utf-8'))
输出
URLError: <urlopen error [Errno 8] _ssl.c:507: EOF occurred in violation of protocol>
我做错了什么?这是什么意思?我该如何解决这个错误?
【问题讨论】:
标签: python http authentication cookies ssl