0

I am trying to get some data from an API but have been getting the error 'dict' object has no attribute 'META' when I try to print it. I am using Requests module for this. Here is the code:

url = "https://coronavirus-map.p.rapidapi.com/v1/summary/region"

    querystring = {"region":"Bangladesh"}

    headers = {
        'x-rapidapi-host': "coronavirus-map.p.rapidapi.com",
        'x-rapidapi-key': "leaving this out :P"
    }

    request = requests.get(url, headers=headers, params=querystring).json()

    print(request.text)

Everything works on Postman. Can anyone help?

1
  • params looks suspicious here, isn't json= or data=? Commented Apr 12, 2020 at 17:44

1 Answer 1

1

It seems like all I had to do is remove the '.text' from the print command. I don't know why I had to do that though. Would be helpful if someone could tell.

So the change was:

print(request)
Sign up to request clarification or add additional context in comments.

2 Comments

Or .json() from the lite above. Having the variable request be a dict seems misleading.
So, the reason for the error is that .json() from the response object returns a dict in this case. (It could also potentially be a list, depending on the JSON data.) And then on the line below you try to print the attribute .text from the response object, but on the dict instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.