I'm trying to use the pylast interface for the Last FM API on my flask web app, and it keeps giving me a ConnectionRefusedError, like this:
2021-08-18 21:48:43,440: Exception on /ajax [POST]
Traceback (most recent call last):
File "/home/pythonanycode/.local/lib/python3.9/site-packages/pylast/init.py", line 939, in _download_response
conn.request(
File "/usr/local/lib/python3.9/http/client.py", line 1253, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.9/http/client.py", line 1299, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.9/http/client.py", line 1248, in endheaders >>self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.9/http/client.py", line 1008, in _send_output >>self.send(msg)
File "/usr/local/lib/python3.9/http/client.py", line 948, in send >>self.connect()
File "/usr/local/lib/python3.9/http/client.py", line 1415, in connect >>super().connect()
File "/usr/local/lib/python3.9/http/client.py", line 919, in connect >>self.sock = self._create_connection(
File "/usr/local/lib/python3.9/socket.py", line 843, in create_connection
raise err
File "/usr/local/lib/python3.9/socket.py", line 831, in create_connection >>sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
I'm using an ajax request for this, and I have flask_cors setup for this with @cross_origin on the appropriate function. The app works fine for me locally. The error's happening on this line when I instantiate the api's main class.
api = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET, username=username, password_hash=password_hash)
Can anyone tell me why I'm getting this error? As far as I know, the Last FM API is whitelisted. Does it have to do with it being an ajax request or the way I'm setting it up? Here is a link to the full pylast code, if that helps (the important part being the LastFMNetwork class): https://github.com/pylast/pylast/blob/master/src/pylast/init.py
I would really appreciate any help with this, since I was very close to getting this to work until I hit this snag. Thanks!