question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow `gspread.oauth()` to look for file in another directory

See original GitHub issue

Is your feature request related to a problem? Please describe. Not really a problem, but I got bitten a bit by it. I used to be using a service account and service_account allows users to store google credentials where they want. This is particularly relevant for the flow I have implemented in my CLI tool to import google sheets to SQL databases (sheetwork) where I require users to put credentials into a .sheetwork folder.

gspread.oauth doesn’t take arguments for filename, but since it uses load_credentials() https://github.com/burnash/gspread/blob/master/gspread/auth.py#L93 I would assume this is possible.

Is there a reason why this might not be allowed? Could it break a few things?

Describe the solution you’d like allow oaut() to take a filename argument that is passed to load_credentials

If you agree that this would be possible, I’d be happy to contribute to the change.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
akochkarevcommented, Nov 14, 2020

Is your feature request related to a problem? Please describe. Not really a problem, but I got bitten a bit by it. I used to be using a service account and service_account allows users to store google credentials where they want. This is particularly relevant for the flow I have implemented in my CLI tool to import google sheets to SQL databases (sheetwork) where I require users to put credentials into a .sheetwork folder.

gspread.oauth doesn’t take arguments for filename, but since it uses load_credentials() https://github.com/burnash/gspread/blob/master/gspread/auth.py#L93 I would assume this is possible.

Is there a reason why this might not be allowed? Could it break a few things?

Describe the solution you’d like allow oaut() to take a filename argument that is passed to load_credentials

If you agree that this would be possible, I’d be happy to contribute to the change.

I faced the same problem when start to use gspread. Workaround is to change default creds location by modifying gspread settings and default function parameters. Not very elegant, but working solution:

import gspread.auth as ga
import mysettings as cfg

def changeUserCredsStorage():

    ga.DEFAULT_CONFIG_DIR = cfg.DEFAULT_SECRETS_DIR

    ga.DEFAULT_CREDENTIALS_FILENAME = os.path.join(
        ga.DEFAULT_CONFIG_DIR, 'credentials.json'
    )
    ga.DEFAULT_AUTHORIZED_USER_FILENAME = os.path.join(
        ga.DEFAULT_CONFIG_DIR, 'authorized_user.json'
    )
    ga.DEFAULT_SERVICE_ACCOUNT_FILENAME = os.path.join(
        ga.DEFAULT_CONFIG_DIR, 'service_account.json'
    )

    ga.load_credentials.__defaults__ = (ga.DEFAULT_AUTHORIZED_USER_FILENAME,)
    ga.store_credentials.__defaults__ = (ga.DEFAULT_AUTHORIZED_USER_FILENAME, 'token')

But now i switch to service accounts and do not use this.

1reaction
bastienboutonnetcommented, Apr 17, 2021

I believe when @burnash gets around to giving another look at the PR it should be good as all the changes they asked for have been implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication — gspread 5.7.0 documentation
Create a new Python file with this code: import gspread gc = gspread.service_account() sh = gc.open("Example spreadsheet") print(sh.sheet1.get('A1')).
Read more >
Using python Gspread Oauth with credentials file saved ...
This function will set all the relevant environmental variables to your directory of choice where the credentials.json file should be kept ...
Read more >
gspread.oauth() does not allow authorized_user_filename to ...
Specifically, os.path.dirname("authorized_user.json") = '' , but os.makedirs() cannot accept an empty string.
Read more >
gspread Documentation - Read the Docs
Create a new Python file with this code: import gspread gc = gspread.oauth() sh = gc.open("Example spreadsheet") print(sh.sheet1.get('A1')).
Read more >
Create and populate folders | Google Drive
a folder is a file with the MIME type application/vnd.google-apps.folder and ... View on GitHub ... public static String createFolder() throws IOException {...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found