Google Cloud Functions - ImportError: cannot import name 'InvalidKeyError' from 'jwt.exceptions'
Google Cloud Functions - ImportError: cannot import name 'InvalidKeyError' from 'jwt.exceptions'
我在执行 Cloud Functions 时在 GCP 中收到以下错误,即使用 Python 3.8 的 Cloud PubSub,下面还有 requirements.txt
中包含的包
我也试过只安装jwt,但得到了同样的错误。只用pyjwt试过,又报同样的错误。两者都试过了,同样的错误。
Requirements.txt:
- atlassian-python-api==3.13.0
- google==3.0.0
- google-api-python-客户端==2.18.0
- google-auth==2.0.1
- google-auth-httplib2==0.1.0
- google-auth-oauthlib==0.4.5
- oauth2client==4.1.3
- oauthlib==3.1.1
- 发送网格==6.8.1
- gspread==4.0.1
- pandas==1.3.2
- jwt==1.2.0
- PyJWT==2.1.0
- 密码学==3.4.8
- rsa==4.7.2
回溯:
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py", line 152, in view_func
function(data, context)
File "/workspace/main.py", line 72, in get_data_from_jira
data = jira_instance.jql("project = PROJECTNAME AND issuetype = 'ISSUETYPE' AND status = 'In Progress'")
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/atlassian/jira.py", line 2418, in jql
return self.get(url, params=params)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/atlassian/rest_client.py", line 264, in get
response = self.request(
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/atlassian/rest_client.py", line 218, in request
response = self._session.request(
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests/sessions.py", line 528, in request
prep = self.prepare_request(req)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests/sessions.py", line 456, in prepare_request
p.prepare(
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests/models.py", line 320, in prepare
self.prepare_auth(auth, url)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests/models.py", line 556, in prepare_auth
r = auth(self)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests_oauthlib/oauth1_auth.py", line 108, in __call__
r.url, headers, _ = self.client.sign(
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 351, in sign
('oauth_signature', self.get_oauth_signature(request)))
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 186, in get_oauth_signature
sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/signature.py", line 742, in sign_rsa_sha1_with_client
return _sign_rsa('SHA-1', sig_base_str, client.rsa_key)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/signature.py", line 617, in _sign_rsa
alg = _get_jwt_rsa_algorithm(hash_algorithm_name)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/signature.py", line 562, in _get_jwt_rsa_algorithm
import jwt.algorithms as jwt_algorithms
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/jwt/algorithms.py", line 5, in <module>
from .exceptions import InvalidKeyError
ImportError: cannot import name 'InvalidKeyError' from 'jwt.exceptions' (/layers/google.python.pip/pip/lib/python3.8/site-packages/jwt/exceptions.py)
我觉得是jwt和pyjwt重名的缘故。 https://github.com/jazzband/djangorestframework-simplejwt/issues/42
我在执行 Cloud Functions 时在 GCP 中收到以下错误,即使用 Python 3.8 的 Cloud PubSub,下面还有 requirements.txt
中包含的包我也试过只安装jwt,但得到了同样的错误。只用pyjwt试过,又报同样的错误。两者都试过了,同样的错误。
Requirements.txt:
- atlassian-python-api==3.13.0
- google==3.0.0
- google-api-python-客户端==2.18.0
- google-auth==2.0.1
- google-auth-httplib2==0.1.0
- google-auth-oauthlib==0.4.5
- oauth2client==4.1.3
- oauthlib==3.1.1
- 发送网格==6.8.1
- gspread==4.0.1
- pandas==1.3.2
- jwt==1.2.0
- PyJWT==2.1.0
- 密码学==3.4.8
- rsa==4.7.2
回溯:
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py", line 152, in view_func
function(data, context)
File "/workspace/main.py", line 72, in get_data_from_jira
data = jira_instance.jql("project = PROJECTNAME AND issuetype = 'ISSUETYPE' AND status = 'In Progress'")
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/atlassian/jira.py", line 2418, in jql
return self.get(url, params=params)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/atlassian/rest_client.py", line 264, in get
response = self.request(
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/atlassian/rest_client.py", line 218, in request
response = self._session.request(
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests/sessions.py", line 528, in request
prep = self.prepare_request(req)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests/sessions.py", line 456, in prepare_request
p.prepare(
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests/models.py", line 320, in prepare
self.prepare_auth(auth, url)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests/models.py", line 556, in prepare_auth
r = auth(self)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/requests_oauthlib/oauth1_auth.py", line 108, in __call__
r.url, headers, _ = self.client.sign(
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 351, in sign
('oauth_signature', self.get_oauth_signature(request)))
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 186, in get_oauth_signature
sig = self.SIGNATURE_METHODS[self.signature_method](base_string, self)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/signature.py", line 742, in sign_rsa_sha1_with_client
return _sign_rsa('SHA-1', sig_base_str, client.rsa_key)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/signature.py", line 617, in _sign_rsa
alg = _get_jwt_rsa_algorithm(hash_algorithm_name)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/oauthlib/oauth1/rfc5849/signature.py", line 562, in _get_jwt_rsa_algorithm
import jwt.algorithms as jwt_algorithms
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/jwt/algorithms.py", line 5, in <module>
from .exceptions import InvalidKeyError
ImportError: cannot import name 'InvalidKeyError' from 'jwt.exceptions' (/layers/google.python.pip/pip/lib/python3.8/site-packages/jwt/exceptions.py)
我觉得是jwt和pyjwt重名的缘故。 https://github.com/jazzband/djangorestframework-simplejwt/issues/42