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 show map with coordinates 
Python :: python swap function 
Python :: how to count specific element in a list python 
Python :: private instance attribute python 
Python :: python type hinting pandas dataframe 
Python :: best fit line python log log scale 
Python :: python counter nested dictionary 
Python :: length of int in python 
Python :: how to print last element in a list python 
Python :: torch tensor to pandas dataframe 
Python :: distinct query in django queryset 
Python :: deep clone 2d list python 
Python :: remote python running line by line visual code 
Python :: python re.search() 
Python :: how to stop auto restart flask python 
Python :: pyspark add_months 
Python :: python slice 
Python :: mkdir if not exists python 
Python :: finding random numbers python 
Python :: Class In Python With Instance Method 
Python :: pytest temp directory 
Python :: how to add createsuper user in django 
Python :: register admin django 
Python :: gradient descent python 
Python :: map two csv files python 
Python :: spark.read.load 
Python :: python flask models user 
Python :: pygame check collision 
Python :: how to find the cosine in python 
Python :: numpy concatenation python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =