ImportError: cannot import name certificate_transparency
See original GitHub issueEnvironment info
Operating System: Ubuntu 16 Python version: 3.6 pyopnessl version: 19.0.0 cryptography version: 2.7 gspread version: 3.1.0
Steps to reproduce
- Use Authlib instead of oauth2client
- Use the code mentioned here.
- Try to open a sheet using
gc.open
.
Stack trace or other output that would be helpful
[Tue Sep 17 16:22:18.385805 2019] [wsgi:error] Traceback (most recent call last):
[Tue Sep 17 16:22:18.385811 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
[Tue Sep 17 16:22:18.385816 2019] [wsgi:error] response = self.full_dispatch_request()
[Tue Sep 17 16:22:18.385821 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
[Tue Sep 17 16:22:18.385827 2019] [wsgi:error] rv = self.handle_user_exception(e)
[Tue Sep 17 16:22:18.385847 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
[Tue Sep 17 16:22:18.385852 2019] [wsgi:error] reraise(exc_type, exc_value, tb)
[Tue Sep 17 16:22:18.385857 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
[Tue Sep 17 16:22:18.385861 2019] [wsgi:error] rv = self.dispatch_request()
[Tue Sep 17 16:22:18.385866 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
[Tue Sep 17 16:22:18.385871 2019] [wsgi:error] return self.view_functions[rule.endpoint](**req.view_args)
[Tue Sep 17 16:22:18.385875 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/myapp/views/event.py", line 64, in validate
[Tue Sep 17 16:22:18.385880 2019] [wsgi:error] worksheet = gc.open("Event Validation Test").sheet1
[Tue Sep 17 16:22:18.385884 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/gspread/client.py", line 123, in open
[Tue Sep 17 16:22:18.385889 2019] [wsgi:error] self.list_spreadsheet_files()
[Tue Sep 17 16:22:18.385893 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/gspread/client.py", line 96, in list_spreadsheet_files
[Tue Sep 17 16:22:18.385898 2019] [wsgi:error] res = self.request('get', url, params=params).json()
[Tue Sep 17 16:22:18.385902 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/gspread/client.py", line 73, in request
[Tue Sep 17 16:22:18.385907 2019] [wsgi:error] headers=headers
[Tue Sep 17 16:22:18.385911 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/requests/sessions.py", line 546, in get
[Tue Sep 17 16:22:18.385916 2019] [wsgi:error] return self.request('GET', url, **kwargs)
[Tue Sep 17 16:22:18.385920 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/client/assertion_session.py", line 43, in request
[Tue Sep 17 16:22:18.385925 2019] [wsgi:error] method, url, headers=headers, data=data, auth=auth, **kwargs)
[Tue Sep 17 16:22:18.385930 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/requests/sessions.py", line 519, in request
[Tue Sep 17 16:22:18.385934 2019] [wsgi:error] prep = self.prepare_request(req)
[Tue Sep 17 16:22:18.385939 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/requests/sessions.py", line 462, in prepare_request
[Tue Sep 17 16:22:18.385944 2019] [wsgi:error] hooks=merge_hooks(request.hooks, self.hooks),
[Tue Sep 17 16:22:18.385949 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/requests/models.py", line 317, in prepare
[Tue Sep 17 16:22:18.385954 2019] [wsgi:error] self.prepare_auth(auth, url)
[Tue Sep 17 16:22:18.385966 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/requests/models.py", line 548, in prepare_auth
[Tue Sep 17 16:22:18.385971 2019] [wsgi:error] r = auth(self)
[Tue Sep 17 16:22:18.385975 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/client/assertion_session.py", line 9, in __call__
[Tue Sep 17 16:22:18.385980 2019] [wsgi:error] self.ensure_refresh_token()
[Tue Sep 17 16:22:18.385984 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/client/assertion_client.py", line 9, in ensure_refresh_token
[Tue Sep 17 16:22:18.385989 2019] [wsgi:error] return self.client.refresh_token()
[Tue Sep 17 16:22:18.385993 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/oauth2/rfc7521/client.py", line 55, in refresh_token
[Tue Sep 17 16:22:18.385998 2019] [wsgi:error] **self._kwargs
[Tue Sep 17 16:22:18.386002 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/oauth2/rfc7523/grant.py", line 24, in sign
[Tue Sep 17 16:22:18.386007 2019] [wsgi:error] expires_at, claims, **kwargs)
[Tue Sep 17 16:22:18.386012 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/oauth2/rfc7523/assertion.py", line 36, in sign_jwt_bearer_assertion
[Tue Sep 17 16:22:18.386016 2019] [wsgi:error] return jwt.encode(header, payload, key)
[Tue Sep 17 16:22:18.386021 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/jose/rfc7519/jwt.py", line 95, in encode
[Tue Sep 17 16:22:18.386025 2019] [wsgi:error] return self._jws.serialize_compact(header, text, key)
[Tue Sep 17 16:22:18.386030 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/jose/rfc7515/jws.py", line 71, in serialize_compact
[Tue Sep 17 16:22:18.386035 2019] [wsgi:error] self._algorithms, jws_header, payload, key, private=True)
[Tue Sep 17 16:22:18.386039 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/jose/util.py", line 12, in prepare_algorithm_key
[Tue Sep 17 16:22:18.386044 2019] [wsgi:error] key = algorithm.prepare_private_key(key)
[Tue Sep 17 16:22:18.386048 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/authlib/jose/rfc7518/_backends/_key_cryptography.py", line 19, in prepare_private_key
[Tue Sep 17 16:22:18.386053 2019] [wsgi:error] return load_pem_private_key(key, password=None, backend=default_backend())
[Tue Sep 17 16:22:18.386058 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/cryptography/hazmat/backends/__init__.py", line 15, in default_backend
[Tue Sep 17 16:22:18.386063 2019] [wsgi:error] from cryptography.hazmat.backends.openssl.backend import backend
[Tue Sep 17 16:22:18.386067 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
[Tue Sep 17 16:22:18.386076 2019] [wsgi:error] from cryptography.hazmat.backends.openssl.backend import backend
[Tue Sep 17 16:22:18.386081 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 18, in <module>
[Tue Sep 17 16:22:18.386085 2019] [wsgi:error] from cryptography import utils, x509
[Tue Sep 17 16:22:18.386090 2019] [wsgi:error] File "/var/www/abc.example.com/public_html/venv/lib/python3.6/site-packages/cryptography/x509/__init__.py", line 7, in <module>
[Tue Sep 17 16:22:18.386095 2019] [wsgi:error] from cryptography.x509 import certificate_transparency
[Tue Sep 17 16:22:18.386099 2019] [wsgi:error] ImportError: cannot import name certificate_transparency
What I have tried so far:
- Checked if the file path is correct.
certificate_transparency.py
does exist in/venv/lib/python3.6/site-packages/cryptography/x509
. - Tried the same on Windows, it works without any error.
- Reinstalled all dependencies, including
pyOpenSSL
. - Tried importing it inside
(venv)
Python console.>>> from cryptography.x509 import certificate_transparency
works fine.
My code:
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_url=token_url,
issuer=issuer,
audience=token_url,
claims=claims,
subject=subject,
key=key,
header=header,
)
scopes = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive',
]
session = create_assertion_session(json_key_file, scopes)
gc = Client(None, session)
worksheet = gc.open("Event Validation Test").sheet1 # this causes the error
requirements.txt
:
asn1crypto==0.24.0
Authlib==0.12.1
blinker==1.4
certifi==2019.6.16
cffi==1.12.3
chardet==3.0.4
Click==7.0
colorama==0.4.1
cryptography==2.7
Flask==1.1.1
Flask-Mail==0.9.1
gspread==3.1.0
httplib2==0.13.1
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
pyasn1==0.4.7
pyasn1-modules==0.2.6
pycparser==2.19
pymaging==0.1
pymaging-png==0.1
pyOpenSSL==19.0.0
requests==2.22.0
rsa==4.0
six==1.12.0
urllib3==1.25.3
Werkzeug==0.15.5
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python Cryptography Error cannot import name ...
The "ImportError: cannot import name certificate_transparency" was resolved using the "cp27mu" builds. When using the "cp27mu" build, ...
Read more >Python Cryptography Error Importerror: Cannot Import Name ...
Python Cryptography Error Importerror: Cannot Import Name Certificate_Transparency. So it's a real shame to see such an important internal integration issue ...
Read more >Cloudera 6. 2 ImportError: cannot import name ...
Cloudera 6. 2 ImportError: cannot import name certificate_transparency ... from azure.adls.webhdfs import PERMISSION_ACTION_ADLS
Read more >cannot import name certificate_transparency when trying to ...
ImportError : cannot import name certificate_transparency when trying to use authlib with gspread on linux. Environment info. Operating System: ...
Read more >ImportError: cannot import name ssl_match_hostname - Help
Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This exception typically occurs on systems where the user has both a pip installed and system installed cryptography package. If you create a virtualenv and run your code inside that what happens?
Huh, well that definitely looks right. I think we need a docker env that can reproduce this to debug much more 😞
There’s definitely something occurring where the import machinery is looking in the wrong place, but I don’t see how.