Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client(None, session) raises AttributeError: 'NoneType' object has no attribute '__module__' (using with Authlib) #773

Closed
ftnext opened this issue May 18, 2020 · 3 comments · Fixed by #774

Comments

@ftnext
Copy link

ftnext commented May 18, 2020

Important: Please do not post usage questions here.
To get a quick response, please ask a question on Stack Overflow using gspread tag.
See existing questions: https://stackoverflow.com/questions/tagged/gspread


Describe the bug
It seems that we can't pass None to gspread.Client, even though the documentation says you can.

gc = Client(None, session)

To Reproduce

  1. pip install gspread authlib (See Environment info)
  2. create main.py (See Code examples)
  3. python main.py

Expected behavior
returns Client (not raise Exception)
expected in https://blog.authlib.org/2018/authlib-for-gspread or https://gspread.readthedocs.io/en/latest/advanced.html#using-authlib

Code example*
ref: https://blog.authlib.org/2018/authlib-for-gspread

import json

from authlib.integrations.requests_client import AssertionSession
from gspread import Client


def create_assertion_session(conf_file, scopes, subject=None):
    with open(conf_file, 'r') as f:
        conf = json.load(f)

    token_url = conf['token_uri']
    issuer = conf['client_email']
    key = conf['private_key']
    key_id = conf.get('private_key_id')

    header = {'alg': 'RS256'}
    if key_id:
        header['kid'] = key_id

    # Google puts scope in payload
    claims = {'scope': ' '.join(scopes)}
    return AssertionSession(
        grant_type=AssertionSession.JWT_BEARER_GRANT_TYPE,
        token_endpoint=token_url,
        issuer=issuer,
        audience=token_url,
        claims=claims,
        subject=subject,
        key=key,
        header=header,
    )


credential_file = "my-credential.json"
scopes = [
    'https://www.googleapis.com/auth/spreadsheets',
    'https://www.googleapis.com/auth/drive',
]
session = create_assertion_session(credential_file, scopes)

gc = Client(None, session)

Environment info:

  • Operating System: macOS (10.14.6)
  • Python version: 3.8.1
  • gspread version: 3.6.0

Authlib 0.14.2

Stack trace

Traceback (most recent call last):
  File "main.py", line 41, in <module>
    gc = Client(None, session)
  File "/Users/.../test_env/lib/python3.8/site-packages/gspread/client.py", line 39, in __init__
    self.auth = convert_credentials(auth)
  File "/Users/.../test_env/lib/python3.8/site-packages/gspread/utils.py", line 50, in convert_credentials
    module = credentials.__module__
AttributeError: 'NoneType' object has no attribute '__module__'

Additional context
temporally workaround: Use gspread.service_account (Not use Authlib)
gc = service_account(credential_file, scopes)
ref: #768

@lepture
Copy link
Contributor

lepture commented May 18, 2020

It was caused by #711

lepture added a commit to lepture/gspread that referenced this issue May 18, 2020
burnash pushed a commit that referenced this issue May 19, 2020
* Allow auth to be None. Fix #773
* Update import path of Authlib
@burnash
Copy link
Owner

burnash commented May 19, 2020

Thank you for reporting this. I'm going to release it on PyPI with the version 3.7.0

@mustafa89
Copy link

@burnash The code on 3.6.0 is quite old now. Would love to get a new release so I can directly pip install rather than using the git commit for this feature.

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants