⬅︎ Back to Cope with JSONDecodeError in requests.get().json() in Python 2 and 3
My immediate thought was why not do something like this, but then I thought for the sake of repetition and clarity your solution makes more sense.import jsonimport requestsresponse = requests.get(url)try: print(response.json())except (json.decoder.JSONDecodeError, ValueError): print("N'est pas JSON")
Comment
My immediate thought was why not do something like this, but then I thought for the sake of repetition and clarity your solution makes more sense.
import json
import requests
response = requests.get(url)
try:
print(response.json())
except (json.decoder.JSONDecodeError, ValueError):
print("N'est pas JSON")