gspread.exceptions.SpreadSheetNotFound
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
Note: this is my first time posting on github, thanks for the great api, if I can get it working :).
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.)
Try to share this spreadsheet with an email address listed in your oAuth credentials. (See #224)
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. :)
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 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.
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.
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.
@Ralithune could you check if this works better: 75b7764?
@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. :)
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']
@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 :/
Thank you, @zugar. That's what I get for not reading the docs all the way through.
@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.
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?
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 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:
- Create the service account as detailed in the instruction here: http://gspread.readthedocs.org/en/latest/oauth2.html
- 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)
- The way around is to impersonate the user via the service account.
- 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
- 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)
- 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.
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, check out #145. There should be some 'read_only' type behavior but we need to decide on this interface.
Basically the answer is "soon."
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.
@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.