Last active
May 12, 2020 17:37
-
-
Save wesinator/e6a0954e5afc637c378882515aec0151 to your computer and use it in GitHub Desktop.
Demonstrate requests .json() JSONDecodeError on empty or invalid input
This file contains hidden or 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, simplejson | |
resp_blank = "https://httpbin.org/status/200" | |
resp_200 = "http://httpstat.us/200" | |
try: | |
requests.get(resp_blank).json() | |
except simplejson.JSONDecodeError as e: | |
print(e) | |
try: | |
requests.get(resp_200).json() | |
except ValueError as e: # equivalent | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment