Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Check status code urllib

import urllib2

req = urllib2.Request('http://www.python.org/fish.html')
try:
    resp = urllib2.urlopen(req)
except urllib2.HTTPError as e:
    if e.code == 404:
        # do something...
    else:
        # ...
except urllib2.URLError as e:
    # Not an HTTP-specific error (e.g. connection refused)
    # ...
else:
    # 200
    body = resp.read()
Comment

Check status code urllib

import urllib.request, urllib.error

url = 'http://www.google.com/asdfsf'
try:
    conn = urllib.request.urlopen(url)
except urllib.error.HTTPError as e:
    # Return code error (e.g. 404, 501, ...)
    # ...
    print('HTTPError: {}'.format(e.code))
except urllib.error.URLError as e:
    # Not an HTTP-specific error (e.g. connection refused)
    # ...
    print('URLError: {}'.format(e.reason))
else:
    # 200
    # ...
    print('good')
Comment

PREVIOUS NEXT
Code Example
Python :: Python Tkinter RadioButton Widget 
Python :: python pass 
Python :: read ms word with python 
Python :: python *args 
Python :: browser = webdriver.firefox() error 
Python :: plt add y gridlines 
Python :: sort dictionary by key 
Python :: timeout socket python 
Python :: Python not readable file 
Python :: python discord embed link 
Python :: colon in array python 
Python :: save bool using playerprefs 
Python :: reading the JSON from a JSON file 
Python :: logarithms python 
Python :: code coverage pytest as html 
Python :: use mongo replica set python 
Python :: reverse array python 
Python :: python bufferedreader 
Python :: import this 
Python :: remove element from list by index 
Python :: Read the entire text file using the read() function 
Python :: count non nan values in column 
Python :: while loop py 
Python :: gradient descent 
Python :: add 1 to all columns in numpy array 
Python :: Converting Dataframe from list Using a list in the dictionary 
Python :: keras normalize 
Python :: invert list python 
Python :: while input is not empty python 
Python :: numpy concatenation 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =