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

Index error list index out of range - pygsheets #261

Closed
Aruloli opened this issue Aug 9, 2018 · 43 comments
Closed

Index error list index out of range - pygsheets #261

Aruloli opened this issue Aug 9, 2018 · 43 comments

Comments

@Aruloli
Copy link

Aruloli commented Aug 9, 2018

Hi Nithin, How are you? My wife having few Google sheets with data asked me to make reports based those data. Before touching her drive, I tested your code in my drive first and it worked perfect. When i tried in my wife's google account it shows following error.
''ss = gc.open('chitra')
File "C:\Users\Aruloli\Python\pygsheets-staging\pygsheets\client.py", line 136, in open
spreadsheet = list(filter(lambda x: x['name'] == title, self.drive.spreadsheet_metadata()))[0]
IndexError: list index out of range''
When I open with gc.open_by_key & gc.open_by_url it works perfect but without many pygsheets methods
Pl help me. Arul

@nithinmurali
Copy link
Owner

what is the version of your pygsheets?

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

Sorry, how to get version?

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

I downloaded this from yours https://github.com/nithinmurali/pygsheets

@nithinmurali
Copy link
Owner

how did you install pygsheets?

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

pip install

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

Python 3.5

@nithinmurali
Copy link
Owner

Okay, this error means, there is no spreadsheet with the given name. are you sure there is a sheet with the name chitra ?

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

I have my own drive where it works perfect. Only in my wife's drive I am getting this problem. Also it opens with both gc.open_by_key & gc.open_by_url . But when I try gc.open("chitra") it gives problem(chitra is the name of the sheet).

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

image

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

With gspread it is getting opened.

credentials = ServiceAccountCredentials.from_json_keyfile_name('ChitraGTCS-eb21b5753afc.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("chitra").sheet1

@nithinmurali
Copy link
Owner

When you use the same service account credentials also you cant open in pygsheets?

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

Thank you so much for devoting your valuable time. Sorry for disturbing you. It is my first ever GitHub query. Your module pygheets is excellant

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

When you use the same service account credentials also you cant open in pygsheets?
1 I tried pygheets first. Since it was giving index error I tried gspread

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

But my wife's email chitra@gatewaytheschool.in belong to school. May be that is the issue

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

But this sheet belong to her ie she is the owner

@nithinmurali
Copy link
Owner

As described in docs, if you wanna access your wife's account make sure the oauth credentials are generated from her account. Else create a service creds and share the sheet to that email.

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

One more thing. My account i was asked for credential authorisation to handle sheets and drive. But i did not receive such thing when I created service account in her login and tried to run the python file.
How to manually generate credentials from her account to approve the scopes ------
SCOPES = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive.metadata.readonly']

@nithinmurali
Copy link
Owner

gc = pygsheets.authorize(outh_file=' path to client_secretxxx.json of her acccount ') try auth like this.

It is supposed to ask her login.

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

Thank you so much. Let me try

@nithinmurali
Copy link
Owner

Else you can also try to use that service account which worked with gspread like this

gc = pygsheets.authorize(service_file=' path to service_creds.json')

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

Thank you so much. It is working perfect. ### Can I try to open another sheet in the same location?

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

Suppose I have two sheets in the same drive, do I need two seperate Service account json files?

@nithinmurali
Copy link
Owner

okay cool. Now it should work for any sheet in her account.

No but all those sheets should be shared with the first service account. Its better to use outh credentials, as then you can acess any sheet in her account.

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

Thank you so much. Let me keep it open this issue few more hours, if you permit so. I have few more queries

@Kordishal
Copy link
Contributor

Kordishal commented Aug 9, 2018

Hi @Aruloli

For security reasons I would delete the picture of the credentials library and your wifes email address.

Additionally delete the API Keys you generated as they are now public and can be used by anyone to access your wifes account, via API.

The other credentials are not necessarily compromised, but I would still re-generate all of them, just to be sure.

And delete the picture of the sheet with personal names & information in it. This is a public forum...

@nithinmurali
Copy link
Owner

True that @Kordishal

Repository owner deleted a comment from Aruloli Aug 9, 2018
@Kordishal
Copy link
Contributor

And the comment with to the sheet. By posting a sheet link, you share it publicly. I could just delete all the information in it.

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

I agree with you. I just deleted the API keys also which I created without knowing the purpose

@nithinmurali
Copy link
Owner

Also @Aruloli, for usage questions please use stackoverflow with pyghseets tag. Github issues are mainly used for reporting issues in the project.

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

I got it. I tried many tags in stackoverflow but failed to get a solution for 2 consecutive days

@nithinmurali
Copy link
Owner

Ohh i see. I am subscribed to the pygsheets tag, so if you use it i would get a notification in few mins.

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

Pl give a link on Complete Task flow of creating Service account>> Give permissions>> Open google sheets. If I could not get your connection I would have dropped this project. Thank you so much.
Shall I close this issue? Suppose I get another issue, if at all, i will open another issue

@Aruloli Aruloli closed this as completed Aug 9, 2018
@nithinmurali
Copy link
Owner

See the docs, http://pygsheets.readthedocs.io/en/latest/authorizing.html everything is explained there.

Also use the staging version of pygsheets, many issues are fixed there,
pip install https://github.com/nithinmurali/pygsheets/archive/staging.zip at moment.

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

gc = pygsheets.authorize(outh_file='client_secretxxx.json')
gc = pygsheets.authorize(service_file='service_creds.json')
Sorry. Do I need to authorise both these files? outh_file & service_file

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

No where I got a clear cut guidance on how to go about except yours

@nithinmurali
Copy link
Owner

NO, Use 1st one if you wanna use oauth authorization, 2 for service account . you only need one of it.

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

After your advice i got very good clarity

@Aruloli
Copy link
Author

Aruloli commented Aug 9, 2018

It got clicked when you advised me to put gc = pygsheets.authorize(service_file='service_creds.json')

@nikkopante
Copy link

Hi! I will be deploying an app thru Heroku. Will this work? I used the authentication method and followed the link and copied it. Will this happen if I deployed it there?

@nikkopante
Copy link

Hi I get a raise SpreadsheetNotFound('Could not find a spreadsheet with title %s.' % title)
when I use
gc = pygsheets.authorize(service_account_file='soemthing.json')

@Kordishal
Copy link
Contributor

Hi,

Please use Stackoverflow for usage questions.

When using a service account you need to share your sheet with the service account email.

And if you do ever post on GitHub again, open a new issue. I only saw this because of an E-Mail notification. Or if you do not want to create a new issue, you can re-open a closed issue.

@nikkopante
Copy link

Noted. Thanks!

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

4 participants