This commit is contained in:
@@ -1394,7 +1394,16 @@ class Session(Closeable, MessageListener, SubListener):
|
|||||||
finally:
|
finally:
|
||||||
self.connection.set_timeout(0)
|
self.connection.set_timeout(0)
|
||||||
|
|
||||||
# If we reach here, the handshake succeeded.
|
# If we reach here, the handshake succeeded; derive
|
||||||
|
# the Shannon cipher keys and mark the session as
|
||||||
|
# connected.
|
||||||
|
buffer.seek(20)
|
||||||
|
with self.__auth_lock:
|
||||||
|
self.cipher_pair = CipherPair(
|
||||||
|
buffer.read(32), buffer.read(32)
|
||||||
|
)
|
||||||
|
self.__auth_lock_bool = True
|
||||||
|
self.logger.info("Connection successfully!")
|
||||||
return
|
return
|
||||||
|
|
||||||
except (ConnectionResetError, OSError, struct.error) as exc:
|
except (ConnectionResetError, OSError, struct.error) as exc:
|
||||||
@@ -1426,17 +1435,18 @@ class Session(Closeable, MessageListener, SubListener):
|
|||||||
)
|
)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# All attempts failed: raise a clear error instead of crashing
|
# All attempts failed: log and raise a clear, user-friendly
|
||||||
# with a low-level struct.error.
|
# error instead of crashing with a low-level struct.error.
|
||||||
raise RuntimeError(
|
friendly_message = (
|
||||||
"Failed to connect to Spotify access point after "
|
"Failed to connect to Spotify after "
|
||||||
f"{max_attempts} attempts"
|
f"{max_attempts} attempts. "
|
||||||
) from last_exc
|
"OAuth login succeeded, but connecting to the Spotify "
|
||||||
buffer.seek(20)
|
"access point timed out or was refused. "
|
||||||
with self.__auth_lock:
|
"This is usually a network or firewall issue."
|
||||||
self.cipher_pair = CipherPair(buffer.read(32), buffer.read(32))
|
)
|
||||||
self.__auth_lock_bool = True
|
self.logger.error("%s Last error: %s", friendly_message, last_exc)
|
||||||
self.logger.info("Connection successfully!")
|
print(friendly_message)
|
||||||
|
raise RuntimeError(friendly_message) from last_exc
|
||||||
|
|
||||||
def content_feeder(self) -> PlayableContentFeeder:
|
def content_feeder(self) -> PlayableContentFeeder:
|
||||||
""" """
|
""" """
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ class OAuth:
|
|||||||
|
|
||||||
def set_code(self, code):
|
def set_code(self, code):
|
||||||
self.__code = code
|
self.__code = code
|
||||||
|
logging.info("OAuth: Callback received, attempting to connect to Spotify...")
|
||||||
|
print("OAuth: Callback received, attempting to connect to Spotify...")
|
||||||
|
|
||||||
def request_token(self):
|
def request_token(self):
|
||||||
if not self.__code:
|
if not self.__code:
|
||||||
@@ -97,6 +99,8 @@ class OAuth:
|
|||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(b"Request doesn't contain 'code'")
|
self.wfile.write(b"Request doesn't contain 'code'")
|
||||||
return
|
return
|
||||||
|
# Store the authorization code and notify the main
|
||||||
|
# process that the callback has been received.
|
||||||
self.server.set_code(query.get("code")[0])
|
self.server.set_code(query.get("code")[0])
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header('Content-type', 'text/html')
|
self.send_header('Content-type', 'text/html')
|
||||||
|
|||||||
Reference in New Issue
Block a user