python - 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!
解决方案
我还没有足够的声誉发表评论,但想警告您,您不小心泄露了您的 API 密钥。如果您不希望其他人利用它,请尽量将其保密;)
推荐阅读
- c# - 发送电子邮件通知的异步代码偶尔发送电子邮件失败
- bash - 如何构建具有许多计算值的制表符分隔的文本文件?
- ruby-on-rails - 我可以重构控制器以减少数据库查询吗?
- python - 请问我应该如何在这段代码中定义“姓氏”?
- python - 如何从 Pandas 数据框中过滤偏移值
- java - 将图像插入 sql server 并检索它
- c - Linux Kernel Dev - cgroup - 如何从组中列出任务的 ID?
- vega-lite - 如何仅在水平轴上将多个图与 vega-lite 链接?
- microsoft-teams - 从 PowerShell 设置我的 Teams 状态
- javascript - Javascript Arrays-Counting up to create dynamic arrays in a forEach 循环