首页 > 解决方案 > requests.get not giving any response

问题描述

I'm new with this whole requests stuff. I tried to get the response from an url and I there were some few times in which I was able to. However, after several tries and adding new lines of code, it stopped working. This is the part of my code where I'm having trouble:

api_request = requests.get("https://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=12345&distance=5&API_KEY=1234-1234-1234-1234")
    api = json.loads(api_request.content)
    city = api[0]["Reporting Area"] 

it tells me that the variable city is not defined, therefore it follows that the requests.get() part has been unsuccessful. I read some other people who had the same problem, but theirs had something to do with Headers (I tried copying the solutions but they didn't seem to work). I also tried copying the url on google and it opened the json file correctly, so it's a Python problem. Thanks!

标签: pythonpython-requests

解决方案


我还没有足够的声誉发表评论,但想警告您,您不小心泄露了您的 API 密钥。如果您不希望其他人利用它,请尽量将其保密;)


推荐阅读