burnash / gspread

Google Sheets Python API

Home Page:https://docs.gspread.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gspread 6.0.0: gspread.oauth() triggers Error 400: redirect_uri_mismatch

Brigidi opened this issue · comments

Describe the bug
oauth() authentication no longer functions when using v6.0.0. The result is a Error 400: redirect_uri_mismatch, which states 'You can’t sign in because this app sent an invalid request. You can try again later, or contact the developer about this issue. Learn more about this error'

To Reproduce
Steps to reproduce the behavior:

  1. pip install gspread
  2. attempt to use gc = gspread.oauth() from the oauth documentation
  3. receive error

Expected behavior
gspread.oauth() is a reliable method for authenticating Google Sheets. I am able to maintain usage by installing v5.12.4.

Code example*

import gspread

gc = gspread.oauth()

sh = gc.open("Example spreadsheet")

print(sh.sheet1.get('A1'))

Additional context
For others who are facing this issue: change your gspread version to v5.12.4 using the following command:

pip install gspread==5.12.4

Hi thank you for raising the issue.

We currently face some issues with the oauth method but not this issue.

I actually tested the oauth with the coming fix (not released yet) and it worked.

Could this be related to #1390 ?

Thanks for responding so promptly — I did not experience any issues with reauth; I was only receiving errors saying I could not be authorized.

I experimented with a few things, most notably, declaring the file path to my credentials and authorized user json files in my config directory:

# gspread access
access = gspread.oauth(
    credentials_filename='/path/to/file/credentials.json',
    authorized_user_filename='/path/to/file/authorized_user.json'
)

Unfortunately, it did not work. The only way for me to resume functionality was to revert to the previous version of gspread.

Hopefully, this issue will be solved with the new release. Happy to do anything I can help, so please let me know if I can be of any assistance. (P.S. — Is there a timeline for when the new release will happen?)

I see, that's a good investigation to check with the file names and check they are being created.

You can specify the flow to use as well, currently due to Google limitations only the local_server_flow works. You can try specifying it.

In terms of timeline we have about 2 PRs to merge then we'll make the patch version 6.0.1

Btw I found the following stack overflow link that mentions the same error and the first response seems to explain some details about the url being used and which must be configured in your Google cloud console, I recommend checking it out .

https://stackoverflow.com/questions/69072079/google-oauth2-integration-error-400-redirect-uri-mismatch

I'll be sure to check it out once I return to my computer. Having read the post on mobile, I'm wondering why my experience would change between v5.12.4 and 6.0.0?

I discovered the problem today bc I started a new project. All legacy projects compile without error.

I merely mention the above as context. I'll continue exploring the problem and will update with any discoveries.

I had a chance to explore more and I think my issue is likely related to #1390. However, one aspect that I just want to note: when I receive the redirect_uri_mismatch error and add the URI to cloud platform, I am able to return results (I'm reading data from a Google Sheets workbook). If I re-run the code then I receive the error again and have to add another uri to cloud platform, which seems to be similar to the re-auth aspect of 1390.

Hopefully, this context is helpful.

Hi @bastienboutonnet your issue should be fixed now with the latest v6.0.1 release, it would be great for us when you get a chance to test it and come back to us if it's fixed or not.

Thank you.

thank you — confirming that v6.0.1 has resolved this issue. I greatly appreciate how quickly you responded to my issue and that you followed up once the patch was released. I can't thank you enough

That's great to read that.

My pleasure.

Thank you for coming back to us.

Closing this issue