0

I am getting the below error in GCP while executing Cloud Functions i.e. Cloud PubSub with Python 3.8, also below is the packages included in the requirements.txt

I have also tried only with jwt installed, but got the same error. tried only with pyjwt, again got the same error. Tried with both, again same error.

Requirements.txt:

  • atlassian-python-api==3.13.0
  • google==3.0.0
  • google-api-python-client==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
  • sendgrid==6.8.1
  • gspread==4.0.1
  • pandas==1.3.2
  • jwt==1.2.0
  • PyJWT==2.1.0
  • cryptography==3.4.8
  • rsa==4.7.2

Traceback:

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)
Beginner
  • 143
  • 1
  • 12
  • 1
    Just to clarify, because this is a namespace collision. Did you UNINSTALL jwt? Or just remove it from your requirements.txt? They have the same installed namespace, and jwt will "win" over PyJWT. So you have to uninstall jwt, and only have PyJWT installed I believe to avoid this. – Gabe Weiss Sep 01 '21 at 15:53
  • @GabeWeiss Sorry, I am new to GCP. I just removed from requirements.txt which I have inside cloud function. Is there a way to uninstall? On using the Cloud Shell, I could see Python 3.7, and some other packages installed, not which I using for the particular cloud functions. – Beginner Sep 01 '21 at 16:28
  • Aaaah, within Cloud Functions that should work (theoretically) :). Have you run this locally? And does it work? – Gabe Weiss Sep 01 '21 at 16:30
  • @GabeWeiss yes its running perfectly in local without any error. Not sure why getting error when executing in Cloud Functions :( – Beginner Sep 01 '21 at 16:34
  • Are you using something like virtualenv to isolate your Python env? – Gabe Weiss Sep 01 '21 at 16:36
  • not using any env in cloud. – Beginner Sep 01 '21 at 16:47
  • Sorry, I meant when you run it locally. – Gabe Weiss Sep 01 '21 at 16:50
  • on running locally, I don't use any environment, but I got the above listed packages with versions installed. The same thing I provided in requirements.txt inside cloud functions, but nothing works in cloud – Beginner Sep 01 '21 at 16:53
  • Right, so what I would do, is install virtualenv (https://docs.python.org/3/library/venv.html). Create a clean environment and do what the Cloud Function will do, which is, once you've activated the clean environment. First run the script, it should fail with packages not found... then do `pip install -r requirements.txt` and run the script and see if it still works. I SUSPECT something in your environment is tweaked just right so it works, but in a clean set up, it'll fail. – Gabe Weiss Sep 01 '21 at 16:58
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/236657/discussion-between-beginner-and-gabe-weiss). – Beginner Sep 01 '21 at 17:03
  • anyone could help me in this? In local, created the env, the code is working fine. Captured the packages installed in the particular env for that code specifically and incorporated the same packages in the requirements.txt inside cloud functions, but still getting the same error again for the env in local, captured the packages using pip freeze > requirements.txt – Beginner Sep 02 '21 at 16:09

1 Answers1

0

I think it's because of the same names in jwt and pyjwt. https://github.com/jazzband/djangorestframework-simplejwt/issues/42

icefantik
  • 16
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 28 '22 at 13:03