gspread icon indicating copy to clipboard operation
gspread copied to clipboard

Issue: spreadsheet not found

Open keith-shep opened this issue 6 years ago • 3 comments

Hello, I have followed all the steps on https://gspread.readthedocs.io/en/latest/oauth2.html and I still get the SpreadsheetNotFound error.

I have previously shared the Google Sheets document with the client email from the JSON file, to which Gmail sends a Delivery Status Notification (Failure) message saying the domain couldn't be found.

Address not found

Your message wasn't delivered to [email protected] because the domain myproj-266608.iam.gserviceaccount.com couldn't be found. Check for typos or unnecessary spaces and try again.

DNS Error: 572720 DNS type 'mx' lookup of myproj-266608.iam.gserviceaccount.com responded with code NXDOMAIN Domain name not found: myproj-266608.iam.gserviceaccount.com

How can I resolve this issue?

Environment info

Operating System: WIN10 Python version: 3.7 gspread version: 3.1.0

Steps to reproduce


from oauth2client.service_account import ServiceAccountCredentials
import gspread

scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'myproj-266608-10d427fb8510.json', scope)

gc = gspread.authorize(credentials)

wks = gc.open("My Sheet").sheet1

Stack trace or other output that would be helpful

Traceback (most recent call last):
  File "C:\Users\Keith\AppData\Local\Programs\Python\Python37\lib\site-packages\gspread\client.py", line 123, in open
    self.list_spreadsheet_files()
  File "C:\Users\Keith\AppData\Local\Programs\Python\Python37\lib\site-packages\gspread\utils.py", line 37, in finditem
    return next((item for item in seq if func(item)))
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Keith\AppData\Local\Programs\Python\Python37\lib\site-packages\gspread\client.py", line 131, in open
    raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound

keith-shep avatar Jan 29 '20 08:01 keith-shep

Hi Keith, you have 2 different issues (which could be related).

  1. The email not found issue is not an error, you are adding a new user as editor of you spreadsheet but you left the tick box ticked with 'send an email to collaborator' which sends an email to a dummy email address that serves only as kind of username for gmail to check you access rights on the spreadsheet and that email address can not receive emails so it will not work, just add the email address and untick the box that send the auto-email.

  2. you try to open a spreadsheet that does not seem to exists. because the error is from the gspread library that went thru all the spreadsheets with the given name and found none.

You can try opening the spreadsheet using it's id like mentioned here: gspread doc using the function open_by_key or open_by_url

lavigne958 avatar Apr 01 '20 19:04 lavigne958

To add to @lavigne958's comment, the open function searches the account's own Google Drive for a sheet of that name. In the case of service accounts, they generally don't have the spreadsheets added to their drive. As he mentions, using open_by_key or open_by_url might be a better option.

aiguofer avatar Apr 03 '20 03:04 aiguofer

No response from issue owner, a proposal for a solution has been given.

Closing this issue.

lavigne958 avatar May 25 '21 20:05 lavigne958