Search code examples
pythongoogle-sheets-apigspread

GSpread pass credentials from Python not JSON


Im using GSpread trying to pass the content on my JSON file (Google API Service Application credentials) as a python Dictionary on my script. Im trying to not to carry a json file wherever I take my script.

I get the following error when I tried to pass a dictionary instead of a json file on the following line:

credentials = ServiceAccountCredentials.from_json_keyfile_name(auth_gdrive(), scope)

TypeError: expected str, bytes or os.PathLike object, not set

### auth_gdrive() returns a dictionary like this:

def auth_gdrive():
    dic = {
        "type": "miauuuuuu",
        "pass": "miauuuu"
    }

Im not allow to show whats really in the dic.


Solution

  • Since I wanted to pass the credentials details from within my application , and not from a json file I couldn't use:

    ServiceAccountCredentials.from_json_keyfile_name()

    from_json_keyfile_name() expects a json file. But looking into the docs I found the following:

    ServiceAccountCredentials.from_json_keyfile_dict()

    This will expect an dict object , this is all I needed.

    Link:

    https://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html

    Thank you everyone again