Home > Blockchain >  i was creating a REST api using flask and while i was about to test it on postman I saw that error
i was creating a REST api using flask and while i was about to test it on postman I saw that error

Time:11-04

  File "c:\Users\kally\rest\code\app.py", line 3, in <module>
    from flask_jwt import JWT
  File "C:\Users\kally\AppData\Roaming\Python\Python310\site-packages\flask_jwt\__init__.py", line 16, in <module>
    import jwt
  File "C:\Users\kally\AppData\Roaming\Python\Python310\site-packages\jwt\__init__.py", line 19, in <module>   
    from .api_jwt import (
  File "C:\Users\kally\AppData\Roaming\Python\Python310\site-packages\jwt\api_jwt.py", line 5, in <module>     
    from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:\Program Files\Python310\lib\collections\__init__.py)

CodePudding user response:

That error

from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' 

is saying to you, that there is no Mapping in collection package. Please check doc

CodePudding user response:

Expanding on my comment:

As described in the documentation, Mapping was moved to collections.abc in v3.3 and is deprecated since v3.9 (while still left visible for backwards compatability until v3.8).

Your error stems from using outdated imports - you would need to upgrade the used pyjwt/jwt - especially its /api_jwt.py. The current version of

https://github.com/jpadilla/pyjwt/blob/master/jwt/api_jwt.py

uses the correct imports since this commit in November 2018.

  • Related