Search code examples
pythonjsonapidata-extraction

Unable to pull data from API in python


My code is below. I am trying to pull data from the COVID-19 API and want to store it in a dataframe to view it and then later use it for analytics purpose in Python.

import pandas as pd
import requests

url = "https://api.covid19api.com/dayone/country/us"
r = requests.get(url)
print(r.json)

I get the following error:

ValueError: Invalid file path or buffer object type: <class 'requests.models.Response'>

What does this mean, and how can I fix it?


Solution

  • Make sure to call the json() method:

    print(r.json())
    #           ^^
    

    Right now you're getting a reference to the method itself.