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

gspread.exceptions.SpreadSheetNotFound #226

Closed
RenSylvain opened this issue Apr 27, 2015 · 28 comments
Closed

gspread.exceptions.SpreadSheetNotFound #226

RenSylvain opened this issue Apr 27, 2015 · 28 comments

Comments

@RenSylvain
Copy link

I read a few of the other issues submitted, nothing seemed to work.

I think I have correctly imported the gspread and oauth2client modules, I run python 2.7.5, and then when I try gc.open("File") it returns a SpreadSheetNotFound error.

I have tried gc.open_by_key(), gc.open_by_url(), same error. Yes, the sheet does exist

Traceback (most recent call last):
File "./gspreadtest.py", line 22, in
ctacc = gc.open("ct").sheet1 ###Note: tried .Sheet1, .sheet1, and just gc.open("ct)
File "/home/ren/Desktop/gspreadtest/gspreadmaster/gspread/client.py", line 150, in open
raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound

Note: this is my first time posting on github, thanks for the great api, if I can get it working :).

@RenSylvain
Copy link
Author

Also, just as an experiment (not sure the market price for this).

I'll pay $1.50 in bitcoin to anybody that posts an answer which solves my problem. (yes that would pretty much mean I am the oracle in this contract, but it'll have to do unless you have a technological way of executing judgement for completion.)

@burnash
Copy link
Owner

burnash commented Apr 28, 2015

Try to share this spreadsheet with an email address listed in your oAuth credentials. (See #224)

@RenSylvain
Copy link
Author

Sir Burnash, I can now update a google spreadsheet via code thanks to you. Please send me your BTC address and I'll send the coin. :)

@Ralithune
Copy link

JFC why isn't this email sharing thing documented ANYWHERE?? I spent the last hour trying to figure out why my newly generated APP / key combination couldn't see anything.

@burnash
Copy link
Owner

burnash commented May 9, 2015

@Ralithune did you read the docs?

That’s it. Don’t forget to share your spreadsheet with an email you have in your json_key[‘client_email’].

That's linked right in the oAuth2 section on the gspread GitHub's page.

@Ralithune
Copy link

You're absolutely right - I found that line after I posted this. There are more than a few people confused about Oauth, and there isn't an official tutorial out there that talks about the Project / App essentially being a separate identity that only has access to objects that have been shared with it.

Maybe we could be a little more verbose, or include that as a final step? It seems like kind of an important thing for anyone trying to accomplish something using Gspread.

Thanks for your work on it by the way.

@burnash
Copy link
Owner

burnash commented May 9, 2015

Maybe we could be a little more verbose, or include that as a final step? It seems like kind of an important thing for anyone trying to accomplish something using Gspread.

I agree. This does make sense.

@burnash
Copy link
Owner

burnash commented May 9, 2015

@Ralithune could you check if this works better: 75b7764?

@Ralithune
Copy link

@burnash That's much better. Personally, I'd have done a screenshot and a whole separate step, but the way you've written it there will get picked up by Google search terms for people running in to exactly the error you helped us through here. :)

@cedricf6
Copy link

Thanks @burnash -
I had the same problem with 'gspread.exceptions.SpreadsheetNotFound'

The main trick is to share the google spreadsheet with the value of json_key['client_email']

@RO-29
Copy link

RO-29 commented May 28, 2015

@burnash I am creating spreadsheets on the the runtime using gdata client which runs into 1000's sometimes.Is there any way I can share the spreadsheets programmatically to the client email which we are talking about here.In a fix actually my code was working before this clientLogin shutdown and now all hell break loose :/

@ayancey
Copy link

ayancey commented Jun 4, 2015

Thank you, @Zugar. That's what I get for not reading the docs all the way through.

@burnash
Copy link
Owner

burnash commented Jun 4, 2015

@RO-29 I'm not sure if it's possible, at least I haven't seen this in the Google API docs yet. If you find how to programmatically share the spreadsheet with the client, please post it here. I'll be happy to add it to the gspread.

@ashwan-iomedia
Copy link

I have Google apps for work account and document sharing is restricted to users within the domain only. So if I try to share the spreadsheet with the service account email (the one inside the json client_email) - I get an error in Google apps that it is restricted from sharing documents outside of the domain. Any thoughts on how to go around this?

@Ralithune
Copy link

I have a similar situation, but my company's google apps policy is not set
to disallow sharing outside the domain.

You can have your administrator go through the steps to create an app under
the title of your work domain to give you a valid client email to share
your document with.

That's the only thing I can think of for your situation. For me, I just
created an app on my personal account and share documents with the app
email ID there.

On Tue, Jul 28, 2015 at 11:30 AM, ashwan-iomedia notifications@github.com
wrote:

I have Google apps for work account and document sharing to is restricted
to users within the domain only. So if I try to share the spreadsheet with
the service account email (the one inside the json client_email) - I get an
error in Google apps that it is restricted from sharing documents outside
of the domain. Any thoughts on how to go around this?


Reply to this email directly or view it on GitHub
#226 (comment).

@ashwan-iomedia
Copy link

@Ralithune thanks - I was able to get this to work! Not sure if the suggestion you made is what I ended up doing.

For anyone in a same boat, these are the steps:

  1. Create the service account as detailed in the instruction here: http://gspread.readthedocs.org/en/latest/oauth2.html
  2. One of the things you need to do is to share the spreadsheet with the service account, which won't work if you have the same use case as mine, where the domain administrator has restricted you to share documents with anyone outside the domain (the service account is outside the domain)
  3. The way around is to impersonate the user via the service account.
  4. To do this you will need administrator access to your domain and then allow the client-api to access the spreadsheet by impersonating a user in your domain
  5. Follow instructions here: http://engineering-blog.alphasights.com/using-service-accounts-to-act-on-behalf-of-your-google-apps-users/ - (from the point of delegating domain wide access)
  6. Then modify the command to include sub="" credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope, sub="Domain_Account_You_Want_To_Impersonate)
    • Domain_Account_You_Want_To_Impersonate is the email address from within the domain, make sure to share the spreadsheet with this user / email
    • The Domain_Account_You_Want_To_Impersonate was also through which I created Service Account.

It worked for me without opening up the domain wide restrictions on our Google Drive setup.

@sharpobject
Copy link

Do I need to have write access to the spreadsheet to do this? I've used the "Share" feature on a spreadsheet I do not have write access to, and I am unable to read it using gspread.

@msuozzo
Copy link
Collaborator

msuozzo commented Oct 12, 2015

@sharpobject, check out #145. There should be some 'read_only' type behavior but we need to decide on this interface.

Basically the answer is "soon."

@pennomi
Copy link

pennomi commented Nov 8, 2015

Not fully reading the docs just bit me also. Would it be appropriate to add a message to the SpreadSheetNotFound error that says "Did you remember to share the spreadsheet with an email address contained in your credentials file?"

I realize that not every SpreadSheetNotFound is caused by this, but it might help a new user get set up.

@kynan
Copy link

kynan commented Nov 27, 2015

@ashwan-iomedia An alternative for avoiding having to share a spreadsheet with a service account email address in the first place is to not use a service account but create an OAuth 2.0 client ID and then use the workflow described in the Google Python API client library docs. You can pass the credentials obtained that way to gspread.authorize.

@ryantuck
Copy link
Contributor

i'm experiencing intermittent SpreadsheetNotFound issues. Approximately 2/3 of the times I run a given script I get the error, and other times it succeeds. Anyone else seeing intermittent behavior like this?

@oztalha
Copy link

oztalha commented Jul 5, 2016

I think the email sharing step is still deeply buried in the instructions list. It could be moved from step 7 in Obtain OAuth2 credentials from Google Developers Console to basic-usage section as a 2nd step. Or the wording of the link should be changed at least, it is deceptive in its current form. Instead of Obtain OAuth2 credentials from Google Developers Console, it could be something like Obtain OAuth2 credentials and set Spreadsheet permissions (then instead of step 7, create a subsection for it --even if it is a single step.

@ghost
Copy link

ghost commented Jul 5, 2016

I had this problem too. You need to open the json key you downloaded in a text editor. Once you have done this, go back to your google spreadsheet and share it with "The email address in not the json code NOT your email account.

Worked like a charm once I had done this

@burnash
Copy link
Owner

burnash commented Jul 5, 2016

@oztalha Since this issue comes up from time to time I have to agree with you. I like the second approach. Could you make PR for it?

@kynan
Copy link

kynan commented Aug 5, 2018

Closed == fixed?

@CreatorGhost
Copy link

A Very Important Note from here : [https://docs.gspread.org/en/latest/oauth2.html#enable-api-access]

Very important! Go to your spreadsheet and share it with a client_email from the step above. Just like you do with any other Google account.
If you don’t do this, you’ll get a gspread.exceptions.SpreadsheetNotFound exception when trying to access this spreadsheet from your application or a script.

This means that you need to share the spreadsheet (by opening the spreadsheet and then clicking on the share button and then just paste the email id) with the "client_email" mail id which is provided in the JSON file that you got from google developer console

eg:

{
  "type": "service_account",
  "project_id": "speeqedy-octane-317516",
  "private_key_id": "8ct0ad00e3e59d49a576012cb515ea89e4e49cc4",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCOlC07MwSYGr54\nMx1+XAXC2k8HrBA/W6I3PZxnG5CUTPL8rJy8Ne2kuXW2k3qN/A0CKf2yUKc0DbIP\nn+LsCDYt6ikTOpb5VeToRMFPlg3dwcghsVFlO2RKVZc1N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JQ2Axa4hh1iP4ri6os1FJHs3aI3T59ETgnttdOdUzRcS+DqWpfaRAoGADnjx\nvQ5kkVX4l6kLZOQ45ou7wRcut8O0tbVQQ0pmQHKRBOf3mnweEHM/URbMGFbd+lNn\njwyUKi2JD+tpHL8J163bmKkm5VmHw7S2u3dikLuahJoqbXP1XIi4pGVpzsqcz5AK\nmUqZSXwpoTGZyoSpXu4UQzbqjuC4sb5GAcFfRyECgYEAqPEqRTfjU48q8X5ZNx/D\nGze5ZU8PpkOr9viffcptt7dF9f/SMyqY6a8oDzm70tN8IHsctoadu/9ZqUAC56XO\nZtc96uppNBHM/ZZr2eXR6iU8fXTkHgA009xYeOIciS/exvlntTn7qeBiLb5DyA2s\nHB/iyGpo6KQBl/rRtcNxQXw=\n-----END PRIVATE KEY-----\n",
  "client_email": "cybor@speedy-octane-313216.iam.gserviceaccount.com",
  "client_id": "102481923285078876543",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/cybor%40speedy-octane-317516.iam.gserviceaccount.com"
}

if this is your JSON file then you need to copy the client_email that is
cybor@speedy-octane-313216.iam.gserviceaccount.com and then share your sheets to this email id.

@MR-Softwares
Copy link

Try to share this spreadsheet with an email address listed in your oAuth credentials. (See #224)

I have done that still same issue persists
line 130, in open
raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound

@lavigne958
Copy link
Collaborator

Hi @MR-Softwares

  • What type of authentication are you using to access your spreadSheet ? ServiceAccount or OAuth ?
  • how do you open your SpreadSheet? using gs.open("spreadsheet-title"), gs.open_by_key("ABCDEGFCA12345") or gs.open_by_url("https://docs.google.com/spreadsheet/ccc?key=0Bm...FE&hl") ?

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

No branches or pull requests