python - 引发连接错误(连接中止,BadStatusLine): using python and Last. fm API

标签 python last.fm

我正在使用 python 调用 Last.fm API 来获取用户信息。获取大约 7000 个用户后出现此错误:

Traceback (most recent call last):

  File "C:/Python27/My Codes & Data/scanuserinfo_100K_3.py", line 48, in <module>

    r=requests.get(host,params=params)

  File "C:\Python27\requests\api.py", line 60, in get

    return request('get', url, **kwargs)

  File "C:\Python27\requests\api.py", line 49, in request

    return session.request(method=method, url=url, **kwargs)

  File "C:\Python27\requests\sessions.py", line 457, in request

    resp = self.send(prep, **send_kwargs)

  File "C:\Python27\requests\sessions.py", line 569, in send

    r = adapter.send(request, **kwargs)

  File "C:\Python27\requests\adapters.py", line 407, in send

    raise ConnectionError(err, request=request)

ConnectionError: ('Connection aborted.', BadStatusLine("''",))

这是我调用 API 的代码:

import requests

API_KEY='####my api key input here#####'

host='http://ws.audioscrobbler.com/2.0/'

params={'method':'user.getInfo',

            'user':'###userid input here####',

            'api_key':API_KEY   
    }

r=requests.get(host,params=params)

有人可以帮我吗?

最佳答案

这可能与他们的 API 限制有关,因为他们希望您不要进行超过 5 次调用/秒 * 60 秒/分钟 * 5 分钟 = 1500 次调用/5 分钟

http://www.last.fm/api/tos

4.4 You will implement suitable caching in accordance with the HTTP headers sent with web service responses. You will not make more than 5 requests per originating IP address per second, averaged over a 5 minute period, without prior written consent. You agree to cache similar artist and any chart data (top tracks, top artists, top albums) for a minimum of one week.

关于python - 引发连接错误(连接中止,BadStatusLine): using python and Last. fm API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26807662/

相关文章:

python - 成功安装软件包后是否应该删除 .whl 安装程序?

python - 按值传递至闭包

api - Last.fm geo.getEvents 返回无效方法 - 此包中没有具有该名称的方法

java - HTTP 发布请求 : target server failed to response

c# - 无法反序列化 XML

python - 使用多处理在 Python 中制作并行版本的 map 函数时出现 Pickle 错误

python - 使用 Apache 运行 Flask 时打印件去了哪里?

python - python中的简单模式匹配

web-services - Last.fm API : Invalid authentication token supplied

javascript - 如何获取 Spotify 应用程序的专辑流派