gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:33:57 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com