gilesknap / gphotos-sync

Google Photos and Albums backup with Google Photos Library API
Apache License 2.0
1.97k stars 163 forks source link

Docker Sync Execution Error #372

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hello, after successfully completing the Oauth2 configuration, when attempting to run a sync operation, the following errors populate the log file:

Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/gphotos_sync/Main.py", line 480, in main self.setup(args, db_path) File "/usr/lib/python3.9/site-packages/gphotos_sync/Main.py", line 329, in setup self.auth.authorize() File "/usr/lib/python3.9/site-packages/gphotos_sync/authorize.py", line 92, in authorize flow.run_local_server(open_browser=False) File "/usr/lib/python3.9/site-packages/google_auth_oauthlib/flow.py", line 505, in run_local_server self.fetch_token(authorization_response=authorization_response) File "/usr/lib/python3.9/site-packages/google_auth_oauthlib/flow.py", line 300, in fetch_token return self.oauth2session.fetch_token(self.client_config["token_uri"], **kwargs) File "/usr/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py", line 244, in fetch_token self._client.parse_request_uri_response( File "/usr/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py", line 220, in parse_request_uri_response response = parse_authorization_code_response(uri, state=state) File "/usr/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 284, in parse_authorization_code_response raise MissingCodeError("Missing code parameter in response.") oauthlib.oauth2.rfc6749.errors.MissingCodeError: (missing_code) Missing code parameter in response. 07-04 20:46:53 WARNING Done.

Prior to my token expiration around June 18th, the script, which I have running in a Docker container on unRAID via template, was working perfectly.

Troubleshooting steps:

I generated a new client secret, verified Google Cloud service account status, and downloaded an updated JSON template file. I then renamed the JSON to the appropriate value for the Docker container and copied the file to the mapped GooglePhotosSync Docker Container config directory. I've confirmed the Google Photos API is active for the corresponding account and permissions are set accordingly for the service account. As a final test, I have created a brand new client ID under Google Cloud Console but was unsuccessful in running the synchronization command with the test client ID. Please help! Thank you in advance.

gilesknap commented 2 years ago

I've not seen this error before.

The oauth flow has changed (because the one we were using is now obsolete) and you do need a new client ID. The procedute to make the client id and secret has changed and is documented here https://gilesknap.github.io/gphotos-sync/main/tutorials/oauth2.html

Are those the steps that you used?

ghost commented 2 years ago

Thank you so much for the quick response. Yes, those instructions align with my personal notes when I set this up and updated my documentation this past January of 2022.

Perhaps I need to recreate the service account. I suppose I can delete everything except the actual project itself and recreate everything related to authentication. Is that what you recommend? I may go ahead and create a debug flow and sniff the applicable traffic on my router and inspect the raw traffic afterwards to identify where the issue occurs in the authentication flow post setup.

What's weird is the actual authentication flow succeeds (I did have to curl the final local redirect address from the docker shell, but nonetheless, the authentication flow still proceeded, appearing successful at that).

gilesknap commented 2 years ago

I did have to curl the final local redirect address from the docker shell

I wonder if that works?

The recommendation is to do all the initial Authenticaion locally on a machine with a browser and then copy the .ghotos-token over to your headless host.

Could you try that?

ghost commented 2 years ago

After performing the authentication flow from within Windows, I was able to successfully transfer the token generated within the specified storage directory to the preferred location (unRAID Share) and execute the script successfully.

Create directory: C:\Users\\AppData\Local\gphotos-sync\gphotos-sync\

Placed client_secret.json (renamed from original download via Google Cloud Console) in the directory created in the previous step.

After installing python 3.10 through Chocolatey (choco install python -Y), from C:\Python310\Scripts:

I specified a test storage directory after creating the directory to ensure no command execution issue.

.\gphotos-sync.exe C:\test

Success!

NOTE: Although previous service accounts and Oauth credentials did show as valid, I removed all associated credentials and created a new service account in addition to new credentials. I wanted to ensure no obsolete authentication methods / flows were being carried over from original credentials.

I believe until the next round of API / Authentication changes, we are good to go. Thank you for assistance and this script.

gilesknap commented 2 years ago

Awesome, thanks for reporting.