iterative / iterative/PyDrive2
LocalWebserver stuck if some other application is running on windows
- Lingua principale
- Python
- Stelle
- 670
- Fork
- 75
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- authentication, backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100