iterative / iterative/PyDrive2

LocalWebserver stuck if some other application is running on windows

Offen
#378 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
670
Forks
75
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Hi,

When something is already running on port 8080, calling:

`gauth.LocalWebserverAuth()
`
successfully opens the browser for OAuth, but after granting access, the redirect to http://localhost:8080/?code=... fails with ERR_CONNECTION_REFUSED.
The command line then just waits indefinitely for the code, because the local server never started on that port.

This happens because LocalWebserverAuth tries to bind to 8080 without checking if it’s free.

Proposed fix:
Check if the port is available before binding, and try alternatives in a small range (e.g., 8080–8085) before raising an error. Example using portpicker:
```python

import portpicker

candidate_ports = [8080] + list(range(8081, 8086))
port_number = None
for p in candidate_ports:
if portpicker.is_port_free(p):
port_number = p
break

if port_number is None:
raise RuntimeError("No free port in range 8080–8085")

print(f"Using port {port_number}")
```

If a non-default port is selected, it would also need to be reflected in the OAuth URL so the redirect URI matches.
Users can pre-register multiple redirect URIs in Google Cloud Console to cover the fallback ports.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start at the gauth.LocalWebserverAuth() entry point and trace how it binds port 8080 and constructs the OAuth redirect. Verify behavior when 8080 is occupied, then confirm that a fallback port is reflected in the redirect and that the command completes after authorization.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
authentication, backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.