Home > Mobile >  How do I use the data that was called when working with an API?
How do I use the data that was called when working with an API?

Time:10-14

I am trying to use an api for the first time, and I need to use the data that was called. When I run my script, I get a <Response [200]> so my code is successful, but how do I view and use the information that was called. Thank you!

CodePudding user response:

If this is how you request the api,

r = requests.get("api")

In this way you'll have a plain text response.

print(r.text)

You can also get json output by doing so

print(r.json())

CodePudding user response:

If you are using requests.

response = requests.get("some url")

response.status_code # get the status code

json_response = response.json() # convert response to json
print(json_response) # you can see dictionary-like structure
print(json_response["arbitrary"]) # you can access data just like normal dictionary

Here's requests documentation

  • Related