iterative / iterative/PyDrive2

LocalWebserver stuck if some other application is running on windows

Abierto
#378 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
670
Forks
75
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
authentication, backend
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.