↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Setting up Python to Connect to Google Sheets

The post follows the author’s work on a migraine-tracking project that uses Twilio and Google Sheets to request survey details by SMS and store them for later doctor’s appointments. It focuses on two issues encountered while using Google APIs and testing the spreadsheet connection.

Reading notes
#

  • The first error came from scope settings when using gspread with Google Sheets API access.
  • The author first thought the configuration file was wrong, but later linked the problem to API version changes and older tutorials.
  • The error was a 403 insufficient authentication scopes message.
  • The scopes that worked were https://spreadsheets.google.com/feeds and https://www.googleapis.com/auth/drive.
  • The issue was tied to gspread being upgraded and based on API v4.
  • A later problem appeared in pytest when the spreadsheet constructor could not read the JSON credentials file.
  • The constructor expected the credential filename path and the sheet name.
  • ../client_secret.json worked in the executor file, but it failed in the test file.
  • A small path test showed that client_secret.json existed while ../client_secret.json did not.
  • Changing the constructor input to client_secret.json fixed the tests.
  • The root directory for pytest was different from the one expected, which explained the path mismatch.
  • The post ends by noting that the next update will cover using the Twilio API with Flask for the migraine survey app.