Answers for "Check if the url is reachable or not in Python"

0

Check if the url is reachable or not in Python

import requests

def url_checker(url):
	try:
		#Get Url
		get = requests.get(url)
		# if the request succeeds 
		if get.status_code == 200:
			return(f"{url}: is reachable")
		else:
			return(f"{url}: is Not reachable, status_code: {get.status_code}")

	#Exception
	except requests.exceptions.RequestException as e:
        # print URL with Errs
		raise SystemExit(f"{url}: is Not reachable \nErr: {e}")
        
# @Zenonymous
Posted by: Guest on March-12-2022

Code answers related to "Check if the url is reachable or not in Python"

Python Answers by Framework

Browse Popular Code Answers by Language