简体   繁体   English

Python机械化浏览器:HTTP错误460

[英]Python Mechanize Browser: HTTP Error 460

I am trying to log into a site using a mechanize browser and getting an HTTP 460 Error which appears to be a made up error so I'm not sure what to make of it. 我试图使用机械化浏览器登录到站点,并收到HTTP 460错误,该错误似乎是人为错误,因此我不确定该怎么做。 Here's the code: 这是代码:

# Browser
br = mechanize.Browser()

# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

br.open("https://foo.com/login")
br.select_form(nr=1)

br[br.form.controls[2].name] = "login@gmail.com" #I can't select the form or controls by name because they change every time
br[br.form.controls[3].name] = "mypassword"
br.method = "post"

response = br.submit()

And here's the error I get with mechanize debug messages turned on: 这是我打开机械化调试消息时遇到的错误:

>>> response = br.submit()
send: 'POST /login/signin.logincomponent_0.signinform HTTP/1.1\r\nAccept-Encodin
g: identity\r\nContent-Length: 599\r\nConnection: close\r\nUser-Agent: Mozilla/5
.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 F
irefox/3.0.1\r\nHost: myaccount.foo.com\r\nCookie: DC=origin1; STUB_SESS=fil
ler%7E%5E%7E0%7Cguid%7E%5E%7E30909BA355883C551B421713700871E5%7E%5E%7E04%2F09%2F
2014; TLTHID=33A41894C02B10C01D1CF554572C7A31; TLTSID=FFDDD892C02A10C01C0BF55457
2C7A31; STUB_SESSION=filler%7E%5E%7E0%7Cstub_sid%7E%5E%7E0%7E%5E%7E04%2F09%2F201
4; JSESSIONID=B6E04AC06D5885942E299F67EE421640\r\nReferer: https://myaccount.foo
.com/login/Signin?\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\
ntLGGfIeGONQt=H4sIAAAAAAAAAJWQvUoDURCFx0AQEmwEa1ES7G4sTKNVCgUhkeBqLbN3Z9cr98%2B5
N25sfBSfQPISKex8Bx%2FA1spCsxo7w9p%2BzDnfYZ7eoFl2YDdRhVX2ULtCWemMd5ZsvNoXFSCDSgeG
vuNCoEd5TSKipxD5vi%2BkY9IqFSkGEoP0C6KMJ4p01kkoTnz3ct5%2B3Xr%2BaMDaENrS2chOn6GhCJ
vDG7zDnkZb9JLIyhZHUx%2BhVVmPF9ba2wb%2F3TZmJymEZJIaFYJydj7LDvL3x5cGwNSXe9Bd6fUYQu
k4C7fwABBho6LjH1o7vkg3yx3Y%2Fus6GqZc%2FWrWL0bnlJ9mNSLf1Sv%2Bx2TIpMSGlu2tJRpRvWDl
%2BATZ7YRMRAIAAA%3D%3D&GkhkHrHNkEGO=N&NgSEvMJNtPPU=login%40gmail.com&tl
BhliqPEpQP=mypassword&NTFAoHFKrewo=184f4acf-1300-4e65-a81d-3092301d87c213970777534
13&signIn=signIn&shs8q2kGs88H=1979975621'
reply: 'HTTP/1.1 460 Unknown\r\n'
header: Content-Type: text/html
header: Content-Length: 0
header: Content-Language: en
header: Cache-Control: no-cache
header: Cache-Control: no-store
header: Cache-Control: must-revalidate
header: Cache-Control: max-age=0
header: Cache-Control: s-maxage=0
header: Cache-Control: private
header: Expires: Wed, 09 Apr 2014 21:09:40 GMT
header: Pragma: no-cache
header: Date: Wed, 09 Apr 2014 21:09:40 GMT
header: Connection: close
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win-amd64\egg\mechanize\_mechanize.py", line 541, in submit
  File "build\bdist.win-amd64\egg\mechanize\_mechanize.py", line 203, in open
  File "build\bdist.win-amd64\egg\mechanize\_mechanize.py", line 255, in _mech_open
mechanize._response.httperror_seek_wrapper: HTTP Error 460: Unknown

Any idea what could be causing a 460 error? 任何想法可能会导致460错误吗? I tried using the submit button on the page instead: 我尝试使用页面上的“提交”按钮代替:

response = br.form.click(br.form.controls[6].name)

but I don't think that I'm using br.click() properly here? 但是我不认为我在这里正确使用br.click()吗?

I determined that the website was using Javascript as part of the login authentication mechanism and therefore Mechanize can't properly emulate a browser. 我确定该网站使用Javascript作为登录身份验证机制的一部分,因此Mechanize无法正确模拟浏览器。 I switched to Selenium which was able to handle the javascript and get me logged in successfully. 我切换到Selenium,它能够处理javascript并成功登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM