kokarare1212/librespot-python

[REQUEST] Errors handling

staniel359 opened this issue · 2 comments

Hello.
I get these errors:

  1. ConnectionError
Nov 16 09:29:26 muffon waitress-serve[608308]: ERROR:main:Exception on /tracks/2fP2NoqPvzIVyAgSa1gIqJ [GET]
Nov 16 09:29:26 muffon waitress-serve[608308]: Traceback (most recent call last):
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
Nov 16 09:29:26 muffon waitress-serve[608308]:     httplib_response = self._make_request(
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 449, in _make_request
Nov 16 09:29:26 muffon waitress-serve[608308]:     six.raise_from(e, None)
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "<string>", line 3, in raise_from
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 444, in _make_request
Nov 16 09:29:26 muffon waitress-serve[608308]:     httplib_response = conn.getresponse()
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/http/client.py", line 1374, in getresponse
Nov 16 09:29:26 muffon waitress-serve[608308]:     response.begin()
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/http/client.py", line 318, in begin
Nov 16 09:29:26 muffon waitress-serve[608308]:     version, status, reason = self._read_status()
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/http/client.py", line 287, in _read_status
Nov 16 09:29:26 muffon waitress-serve[608308]:     raise RemoteDisconnected("Remote end closed connection without"
Nov 16 09:29:26 muffon waitress-serve[608308]: http.client.RemoteDisconnected: Remote end closed connection without response
Nov 16 09:29:26 muffon waitress-serve[608308]: During handling of the above exception, another exception occurred:
Nov 16 09:29:26 muffon waitress-serve[608308]: Traceback (most recent call last):
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
Nov 16 09:29:26 muffon waitress-serve[608308]:     resp = conn.urlopen(
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 785, in urlopen
Nov 16 09:29:26 muffon waitress-serve[608308]:     retries = retries.increment(
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 550, in increment
Nov 16 09:29:26 muffon waitress-serve[608308]:     raise six.reraise(type(error), error, _stacktrace)
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/packages/six.py", line 769, in reraise
Nov 16 09:29:26 muffon waitress-serve[608308]:     raise value.with_traceback(tb)
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
Nov 16 09:29:26 muffon waitress-serve[608308]:     httplib_response = self._make_request(
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 449, in _make_request
Nov 16 09:29:26 muffon waitress-serve[608308]:     six.raise_from(e, None)
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "<string>", line 3, in raise_from
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 444, in _make_request
Nov 16 09:29:26 muffon waitress-serve[608308]:     httplib_response = conn.getresponse()
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/http/client.py", line 1374, in getresponse
Nov 16 09:29:26 muffon waitress-serve[608308]:     response.begin()
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/http/client.py", line 318, in begin
Nov 16 09:29:26 muffon waitress-serve[608308]:     version, status, reason = self._read_status()
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/http/client.py", line 287, in _read_status
Nov 16 09:29:26 muffon waitress-serve[608308]:     raise RemoteDisconnected("Remote end closed connection without"
Nov 16 09:29:26 muffon waitress-serve[608308]: urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Nov 16 09:29:26 muffon waitress-serve[608308]: During handling of the above exception, another exception occurred:
Nov 16 09:29:26 muffon waitress-serve[608308]: Traceback (most recent call last):
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
Nov 16 09:29:26 muffon waitress-serve[608308]:     response = self.full_dispatch_request()
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
Nov 16 09:29:26 muffon waitress-serve[608308]:     rv = self.handle_user_exception(e)
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
Nov 16 09:29:26 muffon waitress-serve[608308]:     rv = self.dispatch_request()
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
Nov 16 09:29:26 muffon waitress-serve[608308]:     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/root/muffon-spotify/main.py", line 44, in convert_track
Nov 16 09:29:26 muffon waitress-serve[608308]:     track = session.content_feeder().load(
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 722, in load
Nov 16 09:29:26 muffon waitress-serve[608308]:     return self.load_track(playable_id, audio_quality_picker, preload,
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 770, in load_track
Nov 16 09:29:26 muffon waitress-serve[608308]:     original = self.__session.api().get_metadata_4_track(
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/core.py", line 97, in get_metadata_4_track
Nov 16 09:29:26 muffon waitress-serve[608308]:     response = self.send("GET",
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/core.py", line 73, in send
Nov 16 09:29:26 muffon waitress-serve[608308]:     response = self.__session.client().send(
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
Nov 16 09:29:26 muffon waitress-serve[608308]:     r = adapter.send(request, **kwargs)
Nov 16 09:29:26 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 547, in send
Nov 16 09:29:26 muffon waitress-serve[608308]:     raise ConnectionError(err, request=request)
Nov 16 09:29:26 muffon waitress-serve[608308]: requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
  1. queue.Empty
Nov 16 03:03:07 muffon waitress-serve[608308]: WARNING:waitress.queue:Task queue depth is 1
Nov 16 03:03:07 muffon waitress-serve[608308]: ERROR:main:Exception on /tracks/0LWkaEyQRkF0XAms8Bg1fC [GET]
Nov 16 03:03:07 muffon waitress-serve[608308]: Traceback (most recent call last):
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
Nov 16 03:03:07 muffon waitress-serve[608308]:     response = self.full_dispatch_request()
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
Nov 16 03:03:07 muffon waitress-serve[608308]:     rv = self.handle_user_exception(e)
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
Nov 16 03:03:07 muffon waitress-serve[608308]:     rv = self.dispatch_request()
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
Nov 16 03:03:07 muffon waitress-serve[608308]:     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/root/muffon-spotify/main.py", line 44, in convert_track
Nov 16 03:03:07 muffon waitress-serve[608308]:     track = session.content_feeder().load(
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 722, in load
Nov 16 03:03:07 muffon waitress-serve[608308]:     return self.load_track(playable_id, audio_quality_picker, preload,
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 783, in load_track
Nov 16 03:03:07 muffon waitress-serve[608308]:     return self.load_stream(file, track, None, preload, halt_listener)
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 737, in load_stream
Nov 16 03:03:07 muffon waitress-serve[608308]:     return CdnFeedHelper.load_track(self.__session, track, file,
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 336, in load_track
Nov 16 03:03:07 muffon waitress-serve[608308]:     key = session.audio_key().get_audio_key(track.gid, file.file_id)
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 274, in get_audio_key
Nov 16 03:03:07 muffon waitress-serve[608308]:     key = callback.wait_response()
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 315, in wait_response
Nov 16 03:03:07 muffon waitress-serve[608308]:     return self.__reference.get(block=False)
Nov 16 03:03:07 muffon waitress-serve[608308]:   File "/usr/local/lib/python3.10/queue.py", line 168, in get
Nov 16 03:03:07 muffon waitress-serve[608308]:     raise Empty
Nov 16 03:03:07 muffon waitress-serve[608308]: _queue.Empty
Nov 16 03:03:07 muffon waitress-serve[608308]: WARNING:waitress.queue:Task queue depth is 2

Is there a way to handle / bypass them or maybe use retry?
Thank you.

There appears to be a problem with the network.
The queue is also related to the error.
Just enclose the code in try-except.

@kokarare1212 Okay, thank you.