Giter VIP home page Giter VIP logo

Comments (4)

lavigne958 avatar lavigne958 commented on June 2, 2024

Hi thank you for raising this issue.

Please provide us the line where your code breaks and the 5 lines of code before that so we can investigate if it's a problem with your code or with gspread.

from gspread.

martin-flower avatar martin-flower commented on June 2, 2024

Here is the complete code

import gspread

def sheet_api():
    gc = gspread.service_account(filename='./config/service_account.json')
    # public spreadsheet - all three references to same spreadsheet
    try:
        sh = gc.open("https://docs.google.com/spreadsheets/d/1gGF4o1C-ytu0aaCdVm6D73wGwPCMvETpqsScTXQzAPM/edit#gid=1164501076")
        print(sh.sheet1.get('A1'))
    except gspread.exceptions.SpreadsheetNotFound:
        pass
    try:
        sh = gc.open("1gGF4o1C-ytu0aaCdVm6D73wGwPCMvETpqsScTXQzAPM")
        print(sh.sheet1.get('A1'))
    except gspread.exceptions.SpreadsheetNotFound:
        pass
    try:
        sh = gc.open("CheckWatt serial numbers")
        print(sh.sheet1.get('A1'))
    except gspread.exceptions.SpreadsheetNotFound:
        pass
    
    # private spreadsheet works
    sh = gc.open("torsdag")
    print(sh.sheet1.get('A1'))

# python3 sheet.py
def main():
    sheet_api()

if __name__ == "__main__":
    main()

from gspread.

lavigne958 avatar lavigne958 commented on June 2, 2024

Hi thank you for sharing.

The issue is located here:

sh = gc.open("https://docs.google.com/spreadsheets/d/1gGF4o1C-ytu0aaCdVm6D73wGwPCMvETpqsScTXQzAPM/edit#gid=1164501076")

As mentioned in the documentation here

The method open() takes a parameter title which is the title of the spreadsheet.

It then searches through all you private + shared filed for the file matching that name.

If you wish to open a public spreadsheet file and you don't own it, please use the open_by_key() method, see example here

from gspread.

martin-flower avatar martin-flower commented on June 2, 2024

Confirmed! open_by_key() is the answer! Thanks for the quick response!

from gspread.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.