Profilo di sawdustloom

Nome sawdustloom
Indirizzo email n/a
Messaggi1
  • Re: Lettura di un file csv da Google Sheets con python
    Forum >> Programmazione Python >> Files e Directory
    I need to read a Google Sheets spreadsheet saved in the Drive of the company for which I am doing this project with Python. Our goal is to create a script that, every time it is run, downloads this file (which is a csv file containing strings showing the geographic coordinates relative to a specific location) and uploads it to the QGIS software.
    ---
    Hello everyone, good day!

    For a work project I have to read, with Python, a Google Sheets spreadsheet saved in the Drive of the company for which I am doing this project. The goal is to create a script that every time it is run downloads this file (which is a csv file that contains strings that represent geographic coordinates associated with a specific location) and loads it into the QGIS software, which then transforms that data and transfers it into a map. The goal, in short, is for QGIS to automatically read the data that is loaded into the .csv file, loading it into the map.

    To do what I proposed, since that file is not a public file, I created a project in Google Cloud, enabled the Google Sheets API and created the related key as a json file to be able to access with the related credentials. I then shared the file I need to download with the email address of the service account associated with the project and I took this script (adapting it to my needs) from the official Google guide to the Sheets API for Python (i.e. from here: https://developers.google.com/.../api/quickstart/python... bitlife )
    The code I wrote (i.e. adapted) I attach it in the question I'm asking, at least it's visible. Obviously it's not the final code, in the sense that it represents a "test" of what I have to do using my own personal file

    . By running it, I get the following error message:

    "

    File "c:\Python311\Lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "c:\Python311\Lib\site-packages\googleapiclient\http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
    googleapiclient.errors.HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/1xJO2I8ZCb34N0GB0ahfhx57zES35oGOJjjIGViZvWs8/values/Loan%21A1%3AG16?alt=json returned "Unable to parse range: Loan!A1:G16". Details: "Unable to parse range: Loan!A1:G16">

    "

    Basically I can't figure out what I'm doing wrong. So I would like 1) feedback on whether my code makes sense to do what I'm trying to do; 2) If there's a way, in which case I'd like to discuss it with you, to do the same thing without using the API; 3) if you could help me get what I'm trying to do by suggesting the specific changes I need to make.

    Thanks a lot for your help!