Skip to content

Instantly share code, notes, and snippets.

@anthoniraj
Created June 16, 2022 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthoniraj/619bfec6dc389290aa0ccda2927163c5 to your computer and use it in GitHub Desktop.
Save anthoniraj/619bfec6dc389290aa0ccda2927163c5 to your computer and use it in GitHub Desktop.
Python Requests Library: Handling Exception for REST API Calls
import requests
url = "https://reqbin.com/echo/post/json"
try:
re = requests.get(url, timeout=5)
if re.ok:
print(re.text)
else:
print("Service Unavailable!")
except Exception:
print("Connection Error")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment