Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

You Have To Use Chrome To Authorize A Python Desktop App API Connection To Google Sheets

TL;DR

If you've setup everything for the Google Sheets API Python Sample.

Some folks reported having to do an incognito browser window or needing to use Firefox. Your milage may vary.

When I ran the app, it opened safari where I clicked through to allow access but then it hung and finally chocked with a message from the browser about not being able to find a localhost server.

Turns out the solution was to copy the URL that shows up in the console and paste it into chrome.

Took me a bit to find that answer via this page. Pasting this here in hopes it helps folks find the answer faster.

Code

$ python quickstart.py
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=111111222222233333333444444.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A55493%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets.readonly&state=1111122223334444455555&access_type=offline
Traceback (most recent call last):
  File "/Users/alans/workshop/quickstart.py", line 69, in <module>
    main()
  File "/Users/alans/workshop/quickstart.py", line 47, in main
    creds = flow.run_local_server(port=0)
  File "/Users/alans/workshop/venv/lib/python3.9/site-packages/google_auth_oauthlib/flow.py", line 478, in run_local_server
    authorization_response = wsgi_app.last_request_uri.replace("http", "https")
AttributeError: 'NoneType' object has no attribute 'replace'