JWT: 'module' object has no attribute 'encode'

前端 未结 7 801
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 23:18

I am getting a Module not found error when using jwt. Here is how I declared it:

def create_jwt_token():
    payload = {
        \"iat\": int(time.time(         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 23:44

    I solved this problem and @josua's answer is correct I would like to answer with details. In my case, pyJwt was already installed. I was using getream client

    And then I was trying to install jwt using: jwt package

    And it is a known issue Issue Related to JWT

    So the actual problem is a quote from Yoshida:

    Unfortunately, no. As of now both libraries use the same jwt module namespace and Python's module system cannot resolve import jwt deterministically.

    So I checked my pip freeze and jwt was installed and I fixed this issue by using these commands:

    pip uninstall jwt==1.0.0
    pip uninstall PyJWT
    pip install PyJWT
    

    And now my code:

    encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
    

    works fine.

提交回复
热议问题