0

my problem is about Web redirect ,, i'm using urllib>getcode() to know what status codes return

so here is my code

import urllib
a = urllib.urlopen("http://www.site.com/incorrect-tDirectory")
a.getcode()

a.getcode() return 200 but actually it's redirect to main page and i've check references that says redirect should return as i remember 300 or 301 but it's not 200 hopefully you got me so my question how to catch the redirection

1 Answer 1

1

urllib2.urlopen() doc page says:

This function returns a file-like object with two additional methods:

geturl() — return the URL of the resource retrieved, commonly used to determine if a redirect was followed
info() — return the meta-information of the page, such as headers, in the form of an mimetools.Message instance (see Quick Reference to HTTP Headers)

urllib.urlopen() actually implements geturl(), too, but it's not put as explicitly in the documentation.

Sign up to request clarification or add additional context in comments.

Comments

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.