开发者

400 bad request error when trying to do a HTTP POST using python mechanize

开发者 https://www.devze.com 2023-03-20 19:48 出处:网络
I\'ve checked the headers info using Live HTTP headers when doing an HTTP POST in firefox, and then I try to do this using mechanize which bro开发者_StackOverflowught me 400 bad request error. Heres m

I've checked the headers info using Live HTTP headers when doing an HTTP POST in firefox, and then I try to do this using mechanize which bro开发者_StackOverflowught me 400 bad request error. Heres my code:

MechBrowser = mechanize.Browser()

LoginUrl = "http://example.com"
LoginHeader = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 GTB7.1 (.NET CLR 3.5.30729)", "referer": "http://example.com"}
LoginData = "example=&hello=hi"

LoginReq = urllib2.Request(LoginUrl, LoginData, LoginHeader)
LoginResposne = MechBrowser.open(LoginReq)

Variable is copied from LiveHTTPHeaders, and I still get 400 error. Is there something missing?


400 is a pretty vague response code. Some causes might be invalid or missing Host or Content-Length headers.


From my bit of webserver programming, I can tell you that you simply have to have "http://example.com?example=&hello=hi".(simply join your url and data with an ampersand.)


There are actually hidden info required for that request which was not captured by LiveHTTPHeaders, so I turned to fiddler for more detailed reports and analysis, problem solved.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号