Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rearrange flow to remove reference to creds #1525

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alifeee
Copy link
Collaborator

@alifeee alifeee commented Oct 25, 2024

I don't fully know how to test this

@lavigne958 please advise :)

@alifeee alifeee self-assigned this Oct 25, 2024
@alifeee alifeee linked an issue Oct 25, 2024 that may be closed by this pull request
@lavigne958
Copy link
Collaborator

The fox looks good ! I just want to run a test to confirm.
To test this code you need to generate oauth credentials, then extract the JSON information and pass them as dict and see what happens 🧐

@alifeee
Copy link
Collaborator Author

alifeee commented Oct 29, 2024

I try to test using

import gspread

gc = gspread.oauth(
    credentials_filename="credentials.json",
    authorized_user_filename="authorised_user.json",
)

sht = gc.open_by_url(
    "https://docs.google.com/spreadsheets/d/89fua83fu983w8fu89s38fu/"
)
ws = sht.sheet1
print(ws.get())

but I get gspread.exceptions.APIError: APIError: [400]: This operation is not supported for this document. I have not used oauth before so it confuses me. Perhaps I will attempt this again soon, but if I do not, feel free to

@lavigne958
Copy link
Collaborator

lavigne958 commented Nov 6, 2024

I try to test using

import gspread

gc = gspread.oauth(
    credentials_filename="credentials.json",
    authorized_user_filename="authorised_user.json",
)

sht = gc.open_by_url(
    "https://docs.google.com/spreadsheets/d/89fua83fu983w8fu89s38fu/"
)
ws = sht.sheet1
print(ws.get())

but I get gspread.exceptions.APIError: APIError: [400]: This operation is not supported for this document. I have not used oauth before so it confuses me. Perhaps I will attempt this again soon, but if I do not, feel free to

the way oauth works is as follow:

  • the first time you run the call to gspread.oauth() it uses the credentials file for authentication
  • then it creates a file called authorized_user.json where it saves some token and some infos.
  • you obtain some credentials to use for any request you make

later (like some hours, days laters)

  • you run the oauth call again
  • it see you authorized_user.json file
  • it tries to use it to authenticate yourself as the token is possibly still valid !
  • if it works you get credentials from that file and you keep making requests
  • if it does not you need to re-authenticate using the original credential file

Here it seems you make a request to a wrong url, the spreadsheet ID look too short and does not look like it's valid, usually it contains letters+numbers and it's case sensitive so it has a mix of lowercase + uppercase letters + numbers.

I tried your code and using my url for my spreadsheet file it works.

Copy link
Collaborator

@lavigne958 lavigne958 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the code and tried using received authentication token, running with new credentials etc. everything works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using oauth_from_dict not working
2 participants