【问题标题】:403 error when calling an API, except I haven't exceeded my amount of call per day调用 API 时出现 403 错误,但我没有超过每天的调用量
【发布时间】:2014-07-14 21:31:35
【问题描述】:

我刚刚获得了一个 ESPN API 密钥,并且刚刚开始尝试使用它。但是,当我尝试调用它时,我得到一个 403 错误,这意味着服务器认为我今天已经调用了太多次数据。澄清一下,我的限制是每天 7,500 个电话。我的代码非常简单,就是看看返回了什么数据:

import requests
print(requests.get('http://api.espn.com/:version/sports?apikey=:apikey'))

API 密钥是正确的,我正在使用 Spyder API。

【问题讨论】:

  • 哦,我正在使用 Python。
  • 您是否将 :version 和 :apikey 替换为正确的版本 (v1) 和您的 apikey?

标签: python http-status-code-403 espn


【解决方案1】:

这是我的工作解决方案:

Python 2.7.5 (default, Mar  9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> version = 'v1'
>>> apikey = '[YOUR KEY HERE]'
>>> print(requests.get('http://api.espn.com/' + version + '/sports?apikey=' + apikey))
<Response [200]>
>>>

这也有效:

Python 2.7.5 (default, Mar  9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> url = 'http://api.espn.com/v1/sports'
>>> params = dict(
...     apikey = '[YOUR KEY HERE]'
... )
>>> print(requests.get(url=url, params=params))
<Response [200]>
>>>

【讨论】:

    猜你喜欢
    • 2013-07-04
    • 2016-10-27
    • 1970-01-01
    • 2021-12-26
    • 2020-07-14
    • 2019-09-03
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多