[GH-ISSUE #95] [BUG] Programs freezes on 2nd login after a failed attempt #11

Closed
opened 2026-02-27 08:11:25 +03:00 by kerem · 4 comments
Owner

Originally created by @PacketSurf on GitHub (Nov 20, 2021).
Original GitHub issue: https://github.com/kokarare1212/librespot-python/issues/95

The program freezes if you try to login after a failed login attempt. It doesn't throw any exception, just completely freezes up. I think it ties into another issue I have, where the program freezes while attempting to reconnect to a session after there is a disconnect.

from librespot.core import Session

username = ..
password = ..
try:
    SESSION = Session.Builder().user_pass("wrong", "creds").create();
except Exception as e:
    print(e)
try:
    SESSION = Session.Builder().user_pass(username, password).create();
except Exception as e:
    #Never throws exception
    print(e)
#Never reaches here
print('login complete.')

To Reproduce
change file to .py
login_test.txt

Originally created by @PacketSurf on GitHub (Nov 20, 2021). Original GitHub issue: https://github.com/kokarare1212/librespot-python/issues/95 The program freezes if you try to login after a failed login attempt. It doesn't throw any exception, just completely freezes up. I think it ties into another issue I have, where the program freezes while attempting to reconnect to a session after there is a disconnect. ``` from librespot.core import Session username = .. password = .. try: SESSION = Session.Builder().user_pass("wrong", "creds").create(); except Exception as e: print(e) try: SESSION = Session.Builder().user_pass(username, password).create(); except Exception as e: #Never throws exception print(e) #Never reaches here print('login complete.') ``` **To Reproduce** change file to .py [login_test.txt](https://github.com/kokarare1212/librespot-python/files/7575386/login_test.txt)
kerem 2026-02-27 08:11:25 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@kokarare1212 commented on GitHub (Nov 21, 2021):

Thank you for your inquiry.
It seems to be stuck when sending data at login and then receiving data afterwards.
Please wait long enough to figure out the details.

<!-- gh-comment-id:974756726 --> @kokarare1212 commented on GitHub (Nov 21, 2021): Thank you for your inquiry. It seems to be stuck when sending data at login and then receiving data afterwards. Please wait long enough to figure out the details.
Author
Owner

@PacketSurf commented on GitHub (Nov 21, 2021):

So it seems to specifically get stuck while trying to receive data from the socket. It calls socket.recv(length) and then never gets passed that point. This is the traceback when I keyboard interrupt:

  SESSION = Session.Builder().user_pass(USERNAME, PW).create();
  File "/opt/anaconda3/lib/python3.8/site-packages/librespot/core.py", line 1224, in create
    session.authenticate(self.login_credentials)
  File "/opt/anaconda3/lib/python3.8/site-packages/librespot/core.py", line 650, in authenticate
    self.__authenticate_partial(credential, False)
  File "/opt/anaconda3/lib/python3.8/site-packages/librespot/core.py", line 972, in __authenticate_partial
    packet = self.cipher_pair.receive_encoded(self.connection)
  File "/opt/anaconda3/lib/python3.8/site-packages/librespot/crypto.py", line 58, in receive_encoded
    header_bytes = self.__receive_cipher.decrypt(connection.read(3))
  File "/opt/anaconda3/lib/python3.8/site-packages/librespot/core.py", line 1481, in read
    return self.__socket.recv(length)
<!-- gh-comment-id:974797370 --> @PacketSurf commented on GitHub (Nov 21, 2021): So it seems to specifically get stuck while trying to receive data from the socket. It calls socket.recv(length) and then never gets passed that point. This is the traceback when I keyboard interrupt: ``` SESSION = Session.Builder().user_pass(USERNAME, PW).create(); File "/opt/anaconda3/lib/python3.8/site-packages/librespot/core.py", line 1224, in create session.authenticate(self.login_credentials) File "/opt/anaconda3/lib/python3.8/site-packages/librespot/core.py", line 650, in authenticate self.__authenticate_partial(credential, False) File "/opt/anaconda3/lib/python3.8/site-packages/librespot/core.py", line 972, in __authenticate_partial packet = self.cipher_pair.receive_encoded(self.connection) File "/opt/anaconda3/lib/python3.8/site-packages/librespot/crypto.py", line 58, in receive_encoded header_bytes = self.__receive_cipher.decrypt(connection.read(3)) File "/opt/anaconda3/lib/python3.8/site-packages/librespot/core.py", line 1481, in read return self.__socket.recv(length) ```
Author
Owner

@kokarare1212 commented on GitHub (Nov 21, 2021):

This has been fixed in the following commit.
The problem was with the initialization of io.BytesIO in the class.
This may be a bug in Python.
Please check it again.
github.com/kokarare1212/librespot-python@bd71ecde46

<!-- gh-comment-id:974813356 --> @kokarare1212 commented on GitHub (Nov 21, 2021): This has been fixed in the following commit. The problem was with the initialization of io.BytesIO in the class. This may be a bug in Python. Please check it again. https://github.com/kokarare1212/librespot-python/commit/bd71ecde46d6c77f0653cb23d1174b0a6ac7540f
Author
Owner

@PacketSurf commented on GitHub (Nov 21, 2021):

Yep, this appears to have fixed any issues I was having. Thank you for the quick response.

<!-- gh-comment-id:974867422 --> @PacketSurf commented on GitHub (Nov 21, 2021): Yep, this appears to have fixed any issues I was having. Thank you for the quick response.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot-python-kokarare1212#11
No description provided.