Raise ConnectionError (connection terminated, BadStatusLine): using python and Last.fm API

I am using python to call the Last.fm API to retrieve user information. This error occurs after extracting about 7000 users:

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("''",)) 

Here is my code to call the 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) 

Can someone help me here?

+5
source share
1 answer

This may be due to their throttling by API, as they expect you to not make more than 5 calls / s * 60 sec / min * 5 min = 1500 calls / 5 min

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

4.4. You implement appropriate caching according to HTTP headers sent with web service responses. You will not earn more than 5 requests per outgoing IP address per second, averaged over a 5 minute period without prior written consent. You agree to cache a similar artist and any chart data (top tracks, top artists, top albums) for at least one week.

+1
source

Source: https://habr.com/ru/post/1206446/


All Articles