I'm coding a short code to check if the url is valid or not. However, when I'm checking for invalid URL it does not respond with any error-ish status code. It just don't run the code.
Can I get some help with this code below:
import requests
import string
# Welcome to IsItDown.py!
# Please write a URL or URLs you want to check. (separated by a comma)
#
# input()
#
# <check for valid URL>
#
# Do you want to start over? (y/n)
# if y:
# elif n: print(Okay. Bye!)
# else: That's not a valid answer
def url_check(urls):
for url in urls:
resp = requests.get(url)
if resp.status_code == 200:
print(f"{url} is up!")
else:
raise Exception(f"{url} is down!")
print("Welcome to IsItDown.py!")
urls = ['google.com .', ' na1v2e12312r.com ']
for index, item in enumerate(urls):
item = item.strip(string.punctuation).strip()
if "http" not in item:
item = "http://" + item
urls[index] = item
print(urls)
try:
url_check(urls)
except Exception as e:
print(e)
It just don't run the code.Really? What output do you get? Is an exception thrown that you're catching? Maybe you could be catching the exception and handling it?NewConnectionErrorand handle that case?