May-04-2019, 10:10 AM
Hi
I want to catch dara from web, but some the web reload for ever (without any error), and some time it catch firewall isuse(HTTP error 500).
But below code, when HTTP error 500, it still read data using, but I want to bypass it. I only want to read data when no error or exceptions.
I want to catch dara from web, but some the web reload for ever (without any error), and some time it catch firewall isuse(HTTP error 500).
But below code, when HTTP error 500, it still read data using, but I want to bypass it. I only want to read data when no error or exceptions.
from urllib.request import Request, urlopen from urllib.error import URLError, HTTPError import requests webinput='https://www.google.com/' try: f=requests.get(webinput,timeout=10).text if len(f>0): print('Web connection is fine') a= else: print('Web server issue') except HTTPError as e: print('Error code:', e.code) except URLError as e: print('We fail to reach server') print('Reason:', e.reason)