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

run_local_server does not seem to release its port if an Exception is raised #338

Closed
IsaacTay opened this issue Mar 19, 2024 · 3 comments
Closed
Labels
api: run Issues related to the Cloud Run API.

Comments

@IsaacTay
Copy link

IsaacTay commented Mar 19, 2024

Environment details

  • OS type and version: Podman container on windows 10 running the python image
  • Python version: 3.10.13
  • pip version: 23.0.1
  • google-auth-oauthlib version: 1.2.0

Steps to reproduce

  1. Run the code example in an environment without browser access (eg. docker container)

Code example

flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
try:
  creds = flow.run_local_server(port=8080)
except:
  ## Adding sleep here doesn't seem help with release the port either
  creds = flow.run_local_server(port=8080, open_browser=False)

Stack trace

Traceback (most recent call last):
  File "example.py", line 4, in test
    creds = flow.run_local_server(port=8080)
  File "/usr/local/lib/python3.10/site-packages/google_auth_oauthlib/flow.py", line 444, in run_local_server
    webbrowser.get(browser).open(auth_url, new=1, autoraise=True)
  File "/usr/local/lib/python3.10/webbrowser.py", line 65, in get
    raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "example.py", line 7, in test
    creds = flow.run_local_server(port=8080, open_browser=False)
  File "/usr/local/lib/python3.10/site-packages/google_auth_oauthlib/flow.py", line 432, in run_local_server
    local_server = wsgiref.simple_server.make_server(
  File "/usr/local/lib/python3.10/wsgiref/simple_server.py", line 154, in make_server
    server = server_class((host, port), handler_class)
  File "/usr/local/lib/python3.10/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/local/lib/python3.10/wsgiref/simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "/usr/local/lib/python3.10/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/local/lib/python3.10/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

@product-auto-label product-auto-label bot added the api: run Issues related to the Cloud Run API. label Mar 19, 2024
@clundin25
Copy link
Contributor

Thank you for bringing this to our attention @IsaacTay !

clundin25 added a commit to clundin25/google-auth-library-python-oauthlib that referenced this issue Mar 21, 2024
@clundin25
Copy link
Contributor

@IsaacTay Can you confirm that #339 fixes your issue?

@clundin25
Copy link
Contributor

Merged #339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: run Issues related to the Cloud Run API.
Projects
None yet
Development

No branches or pull requests

2 participants