Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

SignedJwtAssertionCredentials Support for Python3 #106

@msaniscalchi

Description

@msaniscalchi

I may be missing something here, but this doesn't appear to support Python3 currently. In order to initialize the credentials, you are expected to pass in the private key file's contents as a string, so this would work for Python2:

  with open(KEY_FILE) as f:
    private_key = f.read()

  oauth2credentials = oauth2client.client.SignedJwtAssertionCredentials(
        SERVICE_ACCOUNT_EMAIL, private_key, SCOPE, sub=None)

Doing the same for Python3 would result in a UnicodeDecodeError, as it should be read in binary. Ideally, it would work as follows:

  with open(KEY_FILE, 'rb') as f:
    private_key = f.read()

  oauth2credentials = oauth2client.client.SignedJwtAssertionCredentials(
        SERVICE_ACCOUNT_EMAIL, private_key, SCOPE, sub=None)

However, while it will make it past the initialization step (it probably shouldn't), it will throw a TypeError later when you attempt to do a refresh because crypto.load_pkcs12(key, password) is expecting the key to be a string.

The easiest solution that comes to mind is to handle the private key differently depending on whether it is a str or bytes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions