Created
June 16, 2022 23:16
-
-
Save anthoniraj/619bfec6dc389290aa0ccda2927163c5 to your computer and use it in GitHub Desktop.
Python Requests Library: Handling Exception for REST API Calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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