gspread icon indicating copy to clipboard operation
gspread copied to clipboard

gspread.exceptions.SpreadSheetNotFound

Open RenSylvain opened this issue 11 years ago • 28 comments

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 avatar Apr 27 '15 23:04 RenSylvain

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.)

RenSylvain avatar Apr 28 '15 01:04 RenSylvain

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

burnash avatar Apr 28 '15 11:04 burnash

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. :)

RenSylvain avatar May 02 '15 05:05 RenSylvain

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.

Ralithune avatar May 09 '15 01:05 Ralithune

@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.

burnash avatar May 09 '15 10:05 burnash

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.

Ralithune avatar May 09 '15 17:05 Ralithune

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 avatar May 09 '15 17:05 burnash

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

burnash avatar May 09 '15 17:05 burnash

@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. :)

Ralithune avatar May 09 '15 18:05 Ralithune

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']

cedricf6 avatar May 27 '15 09:05 cedricf6

@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 :/

RO-29 avatar May 28 '15 07:05 RO-29

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

ayancey avatar Jun 04 '15 10:06 ayancey

@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.

burnash avatar Jun 04 '15 12:06 burnash

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?

ashwan-iomedia avatar Jul 28 '15 18:07 ashwan-iomedia

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 [email protected] 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 https://github.com/burnash/gspread/issues/226#issuecomment-125704954.

Ralithune avatar Jul 28 '15 18:07 Ralithune

@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.

ashwan-iomedia avatar Jul 28 '15 19:07 ashwan-iomedia

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.

sharpobject avatar Oct 08 '15 12:10 sharpobject

@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."

msuozzo avatar Oct 12 '15 04:10 msuozzo

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.

pennomi avatar Nov 08 '15 17:11 pennomi

@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.

kynan avatar Nov 27 '15 07:11 kynan