Why I got error "gspread.exceptions.NoValidUrlKeyFound" on python?

1k Views Asked by At

I`m new to pyhon and now trying to use google drive API.

I already enabled both Google sheet and Google drive API Access for this Project. and Here are my codes.

import gspread
from oauth2client.service_account import ServiceAccountCredentials

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

json_file_name = '/Users/kimjongyool/Desktop/upbeat-polygon-292119-fd2b4fab4fa1.json'

credentials = ServiceAccountCredentials.from_json_keyfile_name(json_file_name, scope)
gc = gspread.authorize(credentials)

spreadsheet_url = 'https://docs.google.com/spreadsheets/d/1SAci5Is4tQ1uETGKcTCUmBQrFz4C7-wmj3NhsYgKAWc/edit#gid=0'
doc = gc.open_by_url('spreadsheet_url')

If I run this, I get error message "gspread.exceptions.NoValidUrlKeyFound "

Have searched here and there and still not found any solutions for it. Please help!

1

There are 1 best solutions below

1
On

There's a typo in your code in this line:

doc = gc.open_by_url('spreadsheet_url')

The variable name should go without quote chars ('). This is corrected version:

doc = gc.open_by_url(spreadsheet_url)