简体   繁体   中英

Python Mechanize Value Error when opening a website

when I try to open "twitter.com" with mechanize, it gives me a value error - too many packets to unpack.

br.set_handle_refresh( mechanize._http.HTTPRefreshProcessor(), max_time = 1 )

br.addheaders = [ ( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36" ) ]

br.open("https://twitter.com/signup/")

Is there any way to get it to work?

No-no, it's not about twitter specifically, it's just about the way you specified addheaders - it is supposed to be a list of 2-item tuples - first item in each of the tuple is a header name and the second - header value. In your case, it should be:

br.addheaders = [ ('user-agent', "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36" ) ]

( documentation reference )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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