carbonblack / cbapi-python

Carbon Black API - Python language bindings
Other
147 stars 86 forks source link

[BUG] ImportError: cannot import name 'Mapping' from 'collections' for python 3.10 (maybe 3.9 also) #298

Closed mccluret closed 2 years ago

mccluret commented 2 years ago

cbapi == 1.7.5

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

The above is old syntax and was deprecated in 3.10 (maybe 3.9, not too sure) and should be imported from collections.abc Looks like the error is actually not your package but in https://pypi.org/project/attrdict/ I will create an issue for that but it appears that package might be abandoned.

Traceback File ".../packages/cbapi/connection.py", line 32, in from .auth import CredentialStoreFactory, Credentials File ".../packages/cbapi/auth.py", line 3, in import attrdict File ".../packages/attrdict/init.py", line 5, in from attrdict.mapping import AttrMap File ".../packages/attrdict/mapping.py", line 4, in from collections import Mapping ImportError: cannot import name 'Mapping' from 'collections'

Another explanation of the issue on another repo: https://github.com/rmartin16/qbittorrent-api/issues/45

avanbrunt-cb commented 2 years ago

@mccluret Thanks for reaching out we will look into fixing this issue. If you are using cbapi-python for the Carbon Black Cloud then we would recommend switching to https://github.com/carbonblack/carbon-black-cloud-sdk-python as this is what we support for that product. If you are an EDR or App Control user then this is the correct package to use

sevdog commented 2 years ago

The deprecation warning states:

attrdict/mixins.py:5: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working                                                          
    from collections import Mapping, MutableMapping, Sequence  

Since attrdict is no longer maintained it should be vendored (like it was done here https://github.com/rmartin16/qbittorrent-api/commit/fd1fabf9968c220add00b4f6e03a67c8726f48e4) or a supported alternative should be used instead.

pirofti commented 2 years ago

I have also ran into this issue and decided to fix this and release it on PyPI as AttrDict3. Feel free to use it or open issues on the forked repository. After install, you should not have to modify anything in your code-base.

dganev-cb commented 2 years ago

The version of the attrdict is vendored now and the CbAPI 1.7.8 is released with the fix included please update to the new version.

$ pip install --upgrade cbapi
$ pip install cbapi==1.7.8