Saturday 15 March 2014

python - How do you view the request headers that mechanize is using? -


I am trying to submit some data programmatically to a form. I'm having a small problem which makes the server "I do not like" which I'm sending it to. Disappointingly, there is no error message, or anything that can help to diagnose the problem, they all spit on the same page that I started when I entered the br.submit () Was hit.

When I click the submit button manually in the browser, the resulting page shows a small "success"! message. No such message is displayed when submitting through the script; Additionally, no changes are being sent to the server in fact. This is quite strange, and for the first time I have faced this behavior.

With excavation through mechanize docs, it states that for diagnosing these weird, difficult issues, it is a request that in fact the best way to copy the header presented by the browser is best.

My question is, how do I see that when I call br.submit ()

column code , before> location = 'http://ww.mysite.com' br = mechanize.Browser () cj = mechanize.LWPCookieJar () br.set_cookiejar (cj) username = MY_USER_NAME password = MY_PASSWORD br.addheaders.append (( 'Authorization', 'basic% s'% base64.encodestring ('% s:% s'% (user name, password)) br.open (location) br.select_form (nr = 0) br ['text'] = 'To submit my junk' # text field ['dropdown 1'] = ['4'] = This is a dropdown of integer values ​​br ['DropDown2'] = ['3'] # E S is a dropdown of br.submit ()

What header are I being sent to when I submit the form?

< Are you asking who is sending your browser or mechanized headers?


Browser Strong>

Like other commentators, you can see the headers sent with a plugin like browser (firefox), developer tools (IE, Chrome and Opera) etc.


Mechanize

With mechanization you can get a copy of the sent header by doing something like

  Import mechanize br = mechanize.Browser () br.open ("http://stackoverflow.com") request = br.request request.header_items ()   

in this case

  [('host', 'stackeroverflow dot com'), ('user-agent', 'python-urlb / 2.7')]   

Other / One Stop

As always for the closing of the debug or if nothing is provided, then you Check that the headers are sent to the network Tip : (such as http.request.uri == "http://stackoverflow.com/") Use a filter

No comments:

Post a Comment