Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider changing/adding config for user-auth port #1958

Closed
edinosma opened this issue Nov 10, 2023 · 0 comments · Fixed by #1919
Closed

Consider changing/adding config for user-auth port #1958

edinosma opened this issue Nov 10, 2023 · 0 comments · Fixed by #1919
Labels
Bug Unexpected problem or unintended behavior that needs to be fixed

Comments

@edinosma
Copy link
Contributor

System OS

Windows

Python Version

3.8 (CPython)

Install Source

pip / PyPi

Install version / commit hash

v4.2.1

Expected Behavior vs Actual Behavior

I expect to be able to successfully authenticate into spotDL, but instead the program crashes with the error OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions. Running the program as administrator did not help.

Steps to reproduce - Ensure to include actual links!

  1. Run spotdl download query saved --user-auth
  2. Authenticate through Spotify

Traceback

C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotdl\console\entry_point.py:125 in console_entry_point                                                     │
│                                                                                                                      │
│   122 │   try:                                                                                                       │
│   123 │   │   # Pick the operation to perform                                                                        │
│   124 │   │   # based on the name and run it!                                                                        │
│ ❱ 125 │   │   OPERATIONS[arguments.operation](                                                                       │
│   126 │   │   │   query=arguments.query,                                                                             │
│   127 │   │   │   downloader=downloader,                                                                             │
│   128 │   │   )                                                                                                      │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotdl\console\download.py:25 in download                                                                    │
│                                                                                                                      │
│   22 │   """                                                                                                         │
│   23 │                                                                                                               │
│   24 │   # Parse the query                                                                                           │
│ ❱ 25 │   songs = get_simple_songs(                                                                                   │
│   26 │   │   query,                                                                                                  │
│   27 │   │   use_ytm_data=downloader.settings["ytm_data"],                                                           │
│   28 │   │   playlist_numbering=downloader.settings["playlist_numbering"],                                           │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotdl\utils\search.py:262 in get_simple_songs                                                               │
│                                                                                                                      │
│   259 │   │   │   │   │   # Append to songs                                                                          │
│   260 │   │   │   │   │   songs.append(Song.from_dict(track))                                                        │
│   261 │   │   else:                                                                                                  │
│ ❱ 262 │   │   │   songs.append(Song.from_search_term(request))                                                       │
│   263 │                                                                                                              │
│   264 │   for song_list in lists:                                                                                    │
│   265 │   │   logger.info(                                                                                           │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotdl\types\song.py:163 in from_search_term                                                                 │
│                                                                                                                      │
│   160 │   │   - The Song object.                                                                                     │
│   161 │   │   """                                                                                                    │
│   162 │   │                                                                                                          │
│ ❱ 163 │   │   raw_search_results = Song.search(search_term)                                                          │
│   164 │   │                                                                                                          │
│   165 │   │   if len(raw_search_results["tracks"]["items"]) == 0:                                                    │
│   166 │   │   │   raise SongError(f"No results found for: {search_term}")                                            │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotdl\types\song.py:144 in search                                                                           │
│                                                                                                                      │
│   141 │   │   - The raw search results                                                                               │
│   142 │   │   """                                                                                                    │
│   143 │   │   spotify_client = SpotifyClient()                                                                       │
│ ❱ 144 │   │   raw_search_results = spotify_client.search(search_term)                                                │
│   145 │   │                                                                                                          │
│   146 │   │   if raw_search_results is None:                                                                         │
│   147 │   │   │   raise SongError(f"Spotipy error, no response: {search_term}")                                      │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotipy\client.py:587 in search                                                                              │
│                                                                                                                      │
│    584 │   │   │   │   - market - An ISO 3166-1 alpha-2 country code or the string                                   │
│    585 │   │   │   │   │   │      from_token.                                                                        │
│    586 │   │   """                                                                                                   │
│ ❱  587 │   │   return self._get(                                                                                     │
│    588 │   │   │   "search", q=q, limit=limit, offset=offset, type=type, market=market                               │
│    589 │   │   )                                                                                                     │
│    590                                                                                                               │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotdl\utils\spotify.py:195 in _get                                                                          │
│                                                                                                                      │
│   192 │   │   retries = self.max_retries  # type: ignore # pylint: disable=E1101                                     │
│   193 │   │   while response is None:                                                                                │
│   194 │   │   │   try:                                                                                               │
│ ❱ 195 │   │   │   │   response = self._internal_call("GET", url, payload, kwargs)                                    │
│   196 │   │   │   except (requests.exceptions.Timeout, requests.ConnectionError) as exc:                             │
│   197 │   │   │   │   retries -= 1                                                                                   │
│   198 │   │   │   │   if retries <= 0:                                                                               │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotipy\client.py:247 in _internal_call                                                                      │
│                                                                                                                      │
│    244 │   │   args = dict(params=params)                                                                            │
│    245 │   │   if not url.startswith("http"):                                                                        │
│    246 │   │   │   url = self.prefix + url                                                                           │
│ ❱  247 │   │   headers = self._auth_headers()                                                                        │
│    248 │   │                                                                                                         │
│    249 │   │   if "content_type" in args["params"]:                                                                  │
│    250 │   │   │   headers["Content-Type"] = args["params"]["content_type"]                                          │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotipy\client.py:238 in _auth_headers                                                                       │
│                                                                                                                      │
│    235 │   │   if not self.auth_manager:                                                                             │
│    236 │   │   │   return {}                                                                                         │
│    237 │   │   try:                                                                                                  │
│ ❱  238 │   │   │   token = self.auth_manager.get_access_token(as_dict=False)                                         │
│    239 │   │   except TypeError:                                                                                     │
│    240 │   │   │   token = self.auth_manager.get_access_token()                                                      │
│    241 │   │   return {"Authorization": "Bearer {0}".format(token)}                                                  │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotipy\oauth2.py:535 in get_access_token                                                                    │
│                                                                                                                      │
│    532 │   │                                                                                                         │
│    533 │   │   payload = {                                                                                           │
│    534 │   │   │   "redirect_uri": self.redirect_uri,                                                                │
│ ❱  535 │   │   │   "code": code or self.get_auth_response(),                                                         │
│    536 │   │   │   "grant_type": "authorization_code",                                                               │
│    537 │   │   }                                                                                                     │
│    538 │   │   if self.scope:                                                                                        │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotipy\oauth2.py:490 in get_auth_response                                                                   │
│                                                                                                                      │
│    487 │   │   ):                                                                                                    │
│    488 │   │   │   # Only start a local http server if a port is specified                                           │
│    489 │   │   │   if redirect_port:                                                                                 │
│ ❱  490 │   │   │   │   return self._get_auth_response_local_server(redirect_port)                                    │
│    491 │   │   │   else:                                                                                             │
│    492 │   │   │   │   logger.warning('Using `%s` as redirect URI without a port. '                                  │
│    493 │   │   │   │   │   │   │      'Specify a port (e.g. `%s:8080`) to allow '                                    │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotipy\oauth2.py:457 in _get_auth_response_local_server                                                     │
│                                                                                                                      │
│    454 │   │   return code                                                                                           │
│    455 │                                                                                                             │
│    456 │   def _get_auth_response_local_server(self, redirect_port):                                                 │
│ ❱  457 │   │   server = start_local_http_server(redirect_port)                                                       │
│    458 │   │   self._open_auth_url()                                                                                 │
│    459 │   │   server.handle_request()                                                                               │
│    460                                                                                                               │
│                                                                                                                      │
│ C:\Users\Edin                                                                                                        │
│ O\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-p │
│ ackages\spotipy\oauth2.py:1303 in start_local_http_server                                                            │
│                                                                                                                      │
│   1300                                                                                                               │
│   1301                                                                                                               │
│   1302 def start_local_http_server(port, handler=RequestHandler):                                                    │
│ ❱ 1303 │   server = HTTPServer(("127.0.0.1", port), handler)                                                         │
│   1304 │   server.allow_reuse_address = True                                                                         │
│   1305 │   server.auth_code = None                                                                                   │
│   1306 │   server.auth_token_form = None                                                                             │
│                                                                                                                      │
│ C:\Program                                                                                                           │
│ Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\socketserver.py:452 in       │
│ __init__                                                                                                             │
│                                                                                                                      │
│   449 │   │   │   │   │   │   │   │   │   self.socket_type)                                                          │
│   450 │   │   if bind_and_activate:                                                                                  │
│   451 │   │   │   try:                                                                                               │
│ ❱ 452 │   │   │   │   self.server_bind()                                                                             │
│   454 │   │   │   except:                                                                                            │
│   455 │   │   │   │   self.server_close()                                                                            │
│                                                                                                                      │
│ C:\Program                                                                                                           │
│ Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\server.py:138 in        │
│ server_bind                                                                                                          │
│                                                                                                                      │
│    135 │                                                                                                             │
│    136 │   def server_bind(self):                                                                                    │
│    137 │   │   """Override server_bind to store the server name."""                                                  │
│ ❱  138 │   │   socketserver.TCPServer.server_bind(self)                                                              │
│    139 │   │   host, port = self.server_address[:2]                                                                  │
│    140 │   │   self.server_name = socket.getfqdn(host)                                                               │
│    141 │   │   self.server_port = port                                                                               │
│                                                                                                                      │
│ C:\Program                                                                                                           │
│ Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\socketserver.py:466 in       │
│ server_bind                                                                                                          │
│                                                                                                                      │
│   463 │   │   """                                                                                                    │
│   464 │   │   if self.allow_reuse_address:                                                                           │
│   465 │   │   │   self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)                                  │
│ ❱ 466 │   │   self.socket.bind(self.server_address)                                                                  │
│   467 │   │   self.server_address = self.socket.getsockname()                                                        │
│   468 │                                                                                                              │
│   469 │   def server_activate(self):

Other details

I'm currently using Python 3.8 from the Windows Store; not sure if that has anything to do with it.
The issue was resolved by stopping the iphlpsvc service in the "Services" program.
This may be different for everybody, so the way I found out which program was taking the :8080 port was by running the command netstat -ano | findstr 8080, then tasklist /FI "pid eq [PID]" (tasklist /svc /FI "pid eq [PID]" if the resulting program was svchost.exe, to get the name of what service was using that port). After some Googling, I found what service it was and that it was safe to disable it in the "Services" program.
Perhaps we can consider changing the port number from 8080 to something else? Or allow the user to customize what port to use in the config?

@edinosma edinosma added the Bug Unexpected problem or unintended behavior that needs to be fixed label Nov 10, 2023
@xnetcat xnetcat linked a pull request Nov 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Unexpected problem or unintended behavior that needs to be fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant