Python Requests Check if Reponse Is Json

July 15, 2019
import requests

url = '...'

r = requests.get(url)
    # possible value: application/json or application/json;charset=utf-8
    if r.status_code == 200 and r.headers['Content-Type'].startswith('application/json'):
        print(r.json())
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.