Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Couldn't you check the http response code using httplib. If it was 200 then the page is valid, if it is anything else (like 404) or an error then it is invalid. </p> <p>See this question: <a href="https://stackoverflow.com/questions/1140661/python-get-http-response-code-from-a-url">What’s the best way to get an HTTP response code from a URL?</a></p> <h2>Update:</h2> <p>Based on your comment it looks like your issue is how you are handling the error. You are only handling IOError issues. In your case you can either handle all errors singularly by switching to: </p> <pre><code>except: return index() </code></pre> <p>You could also build your own exception handler by overriding http_default_error. See <a href="https://stackoverflow.com/questions/1308542/how-to-catch-404-error-in-urllib-urlretrieve">How to catch 404 error in urllib.urlretrieve</a> for more information.</p> <p>Or you can switch to urllib2 which has specific errors, You can then handle the specific errors that urllib2 throws like this:</p> <pre><code>from urllib2 import Request, urlopen, URLError req = Request('http://jfvbhsjdfvbs.com') try: response = urlopen(req) except URLError, e: if hasattr(e, 'reason'): print 'We failed to reach a server.' print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code else: print 'URL is good!' </code></pre> <p>The above code with that will return:</p> <pre><code>We failed to reach a server. Reason: [Errno 61] Connection refused </code></pre> <p>The specifics of each exception class is contained in the urllib.error api documentation.</p> <p>I am not exactly sure how to slot this into your code, because I am not sure exactly what you are trying to do, but IOError is not going to handle the exceptions thrown by urllib.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload