3

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.

1 Answer 1

11

Use response.code

from mechanize import Browser
browser = Browser()
response = browser.open('http://www.google.com')
print response.code
Sign up to request clarification or add additional context in comments.

2 Comments

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!
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.