2

I recently moved from perl to python and am updating some of my scripts which used perls WWW::Mechanize to use python mechanize module.

All good so far but I cant get find the HTTP Status code anywhere? (200, 301, etc)

I've googled and found this but isnt their a way to just view the code?

Getting and trapping HTTP response using Mechanize in Python

Thanks.

Community
  • 1
  • 1
James
  • 241
  • 3
  • 13

1 Answers1

10

Use response.code

from mechanize import Browser
browser = Browser()
response = browser.open('http://www.google.com')
print response.code
enderskill
  • 7,354
  • 3
  • 24
  • 23
  • lol fail. Thanks! I used both ipython and eclipse pydev auto complete on the object and neither game me the option for .code. I've looked for a complete resource of all mechanize funtions with some description or example do you know of one? Thanks again! – James Aug 04 '12 at 16:31
  • I have actually used the `code` property before for some of my projects, but it does not show up when I call `dir(response)`. Good topic for another question though. – enderskill Aug 04 '12 at 18:08