You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromgoogleapiclient.discoveryimportbuildimportgoogle.auth.transport.requestsasrefreshfromgoogle.oauth2.credentialsimportCredentialsimportsysid=sys.argv[1]
defupload_epub_to_play_books():
# Load the OAuth 2.0 credentials from a filecreds=Credentials.from_authorized_user_file('/home/user/scripts/playbooks/credentials.json')
# if not creds.valid:# if creds.refresh_token:# request = refresh.Request()# creds.refresh(request)# if creds.valid:# print("Creds valid and were refreshed")# with open('/home/user/scripts/playbooks/credentials.json', 'w') as token:# token.write(creds.to_json())# else:# print("creds already valid")# Create a Google Play Books API service clientservice=build('books', 'v1', credentials=creds)
# Upload the epub file to Google Play Booksresponse=service.cloudloading().addBook(drive_document_id=id).execute()
print(response)
# Upload an epub file to Google Play Booksupload_epub_to_play_books()
Stack trace
Traceback (most recent call last):
File "/home/user/scripts/playbooks/add_to_playbooks.py", line 33, in <module>
upload_epub_to_play_books()
File "/home/user/scripts/playbooks/add_to_playbooks.py", line 28, in upload_epub_to_play_books
response = service.cloudloading().addBook(drive_document_id=id).execute()
File "/home/user/.local/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/user/.local/lib/python3.9/site-packages/googleapiclient/http.py", line 938, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 401 when requesting https://books.googleapis.com/books/v1/cloudloading/addBook?drive_document_id=1QBcMAaQktHT-LmqKDM90ub0XL3IRzBNW&alt=json returned "Invalid Credentials". Details: "[{'message': 'Invalid Credentials', 'domain': 'global', 'reason': 'authError', 'location': 'Authorization', 'locationType': 'header'}]">
This is really strange, because the script was working just a few months ago. It suddenly stopped working and giving 401 errors. I am 100% confident that the credentials/token are not invalid.
The text was updated successfully, but these errors were encountered:
Environment details
google-api-python-client
version: 2.141.0Steps to reproduce
https://www.googleapis.com/books/v1/mylibrary/bookshelves
Code example
Stack trace
This is really strange, because the script was working just a few months ago. It suddenly stopped working and giving 401 errors. I am 100% confident that the credentials/token are not invalid.
The text was updated successfully, but these errors were encountered: