gphotos-sync: Unable to do first set up using docker container

Issue

Error: AttributeError: 'NoneType' object has no attribute 'replace' when trying to access localhost:8080 to kick-off OAuth process.

Steps to Reproduce

  1. Following these steps after getting the client_secret.json from these steps.

  2. Run docker-compose up (see details below). Output:

gphotos  | 03-06 13:36:01 WARNING  gphotos-sync 0.1.dev1+g208a216 2023-03-06 13:36:01.389495 
  1. Access http://localhost:8080 or http://localhost.mydomain.com:8080 (which also points at 0.0.0.0).

  2. Docker container crashes:

gphotos  | 03-06 13:36:01 WARNING  gphotos-sync 0.1.dev1+g208a216 2023-03-06 13:36:01.389495 
gphotos  | 03-06 13:36:12 ERROR    
gphotos  | Process failed. 
gphotos  | Traceback (most recent call last):
gphotos  |   File "/root/.local/lib/python3.10/site-packages/gphotos_sync/Main.py", line 492, in main
gphotos  |     self.setup(args, db_path)
gphotos  |   File "/root/.local/lib/python3.10/site-packages/gphotos_sync/Main.py", line 341, in setup
gphotos  |     self.auth.authorize()
gphotos  |   File "/root/.local/lib/python3.10/site-packages/gphotos_sync/authorize.py", line 95, in authorize
gphotos  |     flow.run_local_server(
gphotos  |   File "/root/.local/lib/python3.10/site-packages/google_auth_oauthlib/flow.py", line 507, in run_local_server
gphotos  |     authorization_response = wsgi_app.last_request_uri.replace("http", "https")
gphotos  | AttributeError: 'NoneType' object has no attribute 'replace'
gphotos  | Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<redacted>.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary.sharing&state=<redacted>&access_type=offline
gphotos  | 03-06 13:36:12 WARNING  Done. 
gphotos exited with code 1

The error looks similar to this comment here. One “strange” thing is that the redirect_uri here is always http://localhost:8080 even if I access http://localhost.mydomain.com:8080 where localhost.mydomain.com is pointing at 0.0.0.0.

I can follow the URL, which would redirect back to localhost:8080 with the state and code. However, the container has crashed by then. If I restart the container before completing the process, then I get a different error:

gphotos  | 03-06 13:44:57 WARNING  gphotos-sync 0.1.dev1+g208a216 2023-03-06 13:44:57.726472 
gphotos  | 03-06 13:45:01 ERROR    
gphotos  | Process failed. 
gphotos  | Traceback (most recent call last):
gphotos  |   File "/root/.local/lib/python3.10/site-packages/gphotos_sync/Main.py", line 492, in main
gphotos  |     self.setup(args, db_path)
gphotos  |   File "/root/.local/lib/python3.10/site-packages/gphotos_sync/Main.py", line 341, in setup
gphotos  |     self.auth.authorize()
gphotos  |   File "/root/.local/lib/python3.10/site-packages/gphotos_sync/authorize.py", line 95, in authorize
gphotos  |     flow.run_local_server(
gphotos  |   File "/root/.local/lib/python3.10/site-packages/google_auth_oauthlib/flow.py", line 508, in run_local_server
gphotos  |     self.fetch_token(authorization_response=authorization_response)
gphotos  |   File "/root/.local/lib/python3.10/site-packages/google_auth_oauthlib/flow.py", line 300, in fetch_token
gphotos  |     return self.oauth2session.fetch_token(self.client_config["token_uri"], **kwargs)
gphotos  |   File "/root/.local/lib/python3.10/site-packages/requests_oauthlib/oauth2_session.py", line 244, in fetch_token
gphotos  |     self._client.parse_request_uri_response(
gphotos  |   File "/root/.local/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py", line 220, in parse_request_uri_response
gphotos  |     response = parse_authorization_code_response(uri, state=state)
gphotos  |   File "/root/.local/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 278, in parse_authorization_code_response
gphotos  |     raise MismatchingStateError()
gphotos  | oauthlib.oauth2.rfc6749.errors.MismatchingStateError: (mismatching_state) CSRF Warning! State not equal in request and response.
gphotos  | Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<redacted>.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary.sharing&state=<redacted>&access_type=offline
gphotos  | 03-06 13:45:01 WARNING  Done. 
gphotos exited with code 1

Details

gphotos-sync version: 0.1.dev1+g208a216 (from docker exec -ti gphotos gphotos-sync --version)

docker-compose.yaml

version: '3.3'

services:
    gphotos:
        image:  ghcr.io/gilesknap/gphotos-sync:latest
        restart: "no"
        container_name: gphotos
        ports:
            - '8080:8080'
        volumes:
            - ./config:/config
            - ./photos:/storage
        command: "/storage"

Command to run: docker-compose up to start container.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

That worked. The OAuth was generated fine end to end with docker-compose up after adding your suggested lines:

        stdin_open: true # docker run -i
        tty: true        # docker run -t

For completeness, I’ve also tried docker-compose run --service-ports after reading your post and similar guidance.

The experience was a bit flaky. The first couple of times it took very long to load the Redirect URL (http://localhost:8080/?state=<redacted>&code=<redacted>&scope=https://www.googleapis.com/auth/photoslibrary.sharing%20https://www.googleapis.com/auth/photoslibrary.readonly) and the container ended up throwing an error:

03-19 06:28:10 ERROR    
Process failed. 
Traceback (most recent call last):
  File "/root/.local/lib/python3.10/site-packages/gphotos_sync/Main.py", line 506, in main
    self.setup(args, db_path)
  File "/root/.local/lib/python3.10/site-packages/gphotos_sync/Main.py", line 353, in setup
    self.auth.authorize()
  File "/root/.local/lib/python3.10/site-packages/gphotos_sync/authorize.py", line 95, in authorize
    flow.run_local_server(
  File "/root/.local/lib/python3.10/site-packages/google_auth_oauthlib/flow.py", line 446, in run_local_server
    authorization_response = wsgi_app.last_request_uri.replace("http", "https")
AttributeError: 'NoneType' object has no attribute 'replace'
03-19 06:28:10 WARNING  Done. 

However, after a couple of runs, it worked fine somehow, but I couldn’t reproduce again. Nonetheless, I think the docker-compose up with your fixes would be best