-1

I'm learning Python and try to use it in my class project. I'm looking for a way to curl an API and return the response json. For example, the response after curling an API is JSON and how can I return it also as JSON

        response = requests.get("https://github.com/timeline.json")
        response = response.content

return response doesn't return it in json while return with jsonify(reponse) get this error (Object of type bytes is not JSON serializable).

Sorry for my English.

davidism
  • 121,510
  • 29
  • 395
  • 339
Phuc
  • 29
  • 5

1 Answers1

1
response = requests.get("https://github.com/timeline.json")
response_json = response.json()
print(response_json["message"])
print(response_json["documentation_url"])

The method json() returns the json-encoded content of a response as a dict. Additionally, you may want to use the new API at https://api.github.com/events (docs).

David
  • 86
  • 3
  • I did attempt to use .json() earlier, however, some of the character return to it's Unicode form. – Phuc Oct 31 '22 at 09:36