1

Looking for some guidance. I've used pyJWT before and had no issues, but recently moved over to a Mac so I'm wondering if its something with the environment variables I don't know to check. Using Python 3.9, PyCharm and a virtual environment.

Trying to create a JWT, encode it to RS384 algorithm (which is supported according to the documentation at https://pyjwt.readthedocs.io/en/latest/algorithms.html and has worked previously on a Windows Machine).

Created my virtual environment, used PIP3 to install pyJWT and received the error "NotImplementedError: Algorithm 'RS384' could not be found. Do you have cryptography installed?".

I was under the impression that pyJWT would download dependencies but even so I downloaded cyrptography and it still appears to have the issue. I've checked my pip3 list as well as my pyCharm libraries for the virtual environment and everything appears good. Any suggestions on what is going on?

Even the simplest sample code (below) receives this error

Code Sample

import jwt
encoded = jwt.encode({"some": "payload"}, "secret", algorithm="RS384")
print(encoded)

Error Screenshot

PIP3 List

PyCharm Env Setup

sallou
  • 99
  • 9
  • 1
    even if you follow the answer below and get all dependencies sorted, the next error will be about your key. You can't just use a simple string, as you might have used before for HS256, as a key for ES384. You need a real ES384 private key instead. – jps Jun 22 '22 at 19:09
  • Thanks for the info. I was previously using a .pem file I was reading in my Windows project. I was just trying to make it the simplest example possible to rule out other issues, but will note that. Thank you. – sallou Jun 22 '22 at 20:47

1 Answers1

0

Install the PyJWT cryptographic dependencies. Keep in mind that zsh uses square brackets for globbing / pattern matching. That means that if you need to pass literal square brackets as an argument to a command, you either need to escape them or quote the argument like this:

pip3 install 'pyJWT[crypto]'
Beatdown
  • 187
  • 2
  • 7
  • 20
  • Thanks for the suggestion. Two comments: 1) I had tried that earlier per a google search and when I attempt to run that in my terminal I get the following error "zsh: no matches found: pyjwt[crypto]" even though running pip works fine. Side note i'm also using pip3 but I think it should be the same. 2) I was under the impression that pip would install all dependencies, is this not accurate? – sallou Jun 22 '22 at 20:46
  • The fix to my above issue is as follows. I found out that zsh uses square brackets for globbing / pattern matching. That means that if you need to pass literal square brackets as an argument to a command, you either need to escape them or quote the argument like this: pip3 install 'pyJWT[crypto]' rather than pip3 install pyJWT[crypto] – sallou Jun 23 '22 at 13:56
  • Good job! I was going to suggest that you look into zsh as I installed them succesfully with Bash, but you got it. I've edited the answer, could you accept it? Glad you got it sorted! Good luck with the project. – Beatdown Jun 23 '22 at 17:00