Skip to content

Commit 952d2d0

Browse files
committed
Handle case where there is no system browser
1 parent 62d92f7 commit 952d2d0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

gcsa/_services/authentication.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os.path
33
import glob
44
from typing import List
5+
import webbrowser
56

67
from googleapiclient import discovery
78
from google_auth_oauthlib.flow import InstalledAppFlow, WSGITimeout
@@ -93,7 +94,8 @@ def _get_credentials(
9394
save_token: bool,
9495
host: str,
9596
port: int,
96-
bind_addr: str
97+
bind_addr: str,
98+
open_browser: bool = True
9799
) -> Credentials:
98100
credentials = None
99101

@@ -109,7 +111,14 @@ def _get_credentials(
109111
flow = InstalledAppFlow.from_client_secrets_file(credentials_path, scopes)
110112
try:
111113
credentials = flow.run_local_server(
112-
host=host, port=port, bind_addr=bind_addr, timeout_seconds=120
114+
host=host, port=port, bind_addr=bind_addr, timeout_seconds=120,
115+
open_browser=open_browser
116+
)
117+
except webbrowser.Error:
118+
# System has no default browser configured, retry without opening browser
119+
return AuthenticatedService._get_credentials(
120+
token_path, credentials_dir, credentials_file, scopes, save_token, host, port,
121+
bind_addr, open_browser=False
113122
)
114123
except WSGITimeout:
115124
print('Authentication flow timed out. Please try again.')

0 commit comments

Comments
 (0)