Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.10 compatibility #413

Open
mheppner opened this issue Nov 24, 2021 · 7 comments
Open

Python 3.10 compatibility #413

mheppner opened this issue Nov 24, 2021 · 7 comments

Comments

@mheppner
Copy link

String comparison between the Python tuple version is not working with Python 3.10.

Located here:

IS_PYTHON_344_PLUS = platform.python_version_tuple() >= ('3', '4', '4')

platform.python_version_tuple() returns ('3', '10', '0') and '10' is not greater than '4'.

This causes the following error in this section:

AttributeError: module 'asyncio' has no attribute 'async'
caused by <class 'AttributeError'>: module 'asyncio' has no attribute 'async'

I think the comparison should be something like this instead: IS_PYTHON_344_PLUS = [int(v) for v in platform.python_version_tuple()] < [3, 4, 4]

flaviut added a commit to flaviut/pysnmp that referenced this issue Dec 26, 2021
Thanks to @mheppner for finding the issue and reporting the bug.
@antonc42
Copy link

antonc42 commented Jan 10, 2022

Thanks @mheppner and @flaviut.

I ran into this issue as soon as I upgraded to Python 3.10. I applied the patch that @flaviut made to the latest release version (v4.4.12) if anyone is interested: https://github.com/antonc42/pysnmp/tree/antonc42-4.4.12-fix-python3.10

You can install with:
python3 -m pip install --force-reinstall git+https://github.com/antonc42/[email protected]

Or put this in your requirements.txt:
git+https://github.com/antonc42/[email protected]

Or put this in your install_requires in setup.py if your module depends on pysnmp:
'pysnmp @ git+https://github.com/antonc42/[email protected]'

@roumano
Copy link

roumano commented Jan 10, 2022

I just tested it for the home-assistant/core#60350

But it's still crash for me :

janv. 10 18:37:13 rasp hass[488]: 2022-01-10 18:37:13 ERROR (MainThread) [aiohttp.server] Error handling request
janv. 10 18:37:13 rasp hass[488]: Traceback (most recent call last):
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/pysnmp/carrier/asyncio/dgram/base.py", line 93, in openClientMode
janv. 10 18:37:13 rasp hass[488]:     self._lport = getattr(asyncio, 'async')(c)
janv. 10 18:37:13 rasp hass[488]: AttributeError: module 'asyncio' has no attribute 'async'
janv. 10 18:37:13 rasp hass[488]: During handling of the above exception, another exception occurred:
janv. 10 18:37:13 rasp hass[488]: Traceback (most recent call last):
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
janv. 10 18:37:13 rasp hass[488]:     resp = await request_handler(request)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
janv. 10 18:37:13 rasp hass[488]:     resp = await handler(request)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
janv. 10 18:37:13 rasp hass[488]:     return await handler(request)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
janv. 10 18:37:13 rasp hass[488]:     return await handler(request)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/forwarded.py", line 98, in forwarded_middleware
janv. 10 18:37:13 rasp hass[488]:     return await handler(request)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
janv. 10 18:37:13 rasp hass[488]:     return await handler(request)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/ban.py", line 78, in ban_middleware
janv. 10 18:37:13 rasp hass[488]:     return await handler(request)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/auth.py", line 181, in auth_middleware
janv. 10 18:37:13 rasp hass[488]:     return await handler(request)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/view.py", line 137, in handle
janv. 10 18:37:13 rasp hass[488]:     result = await result
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/config/config_entries.py", line 157, in post
janv. 10 18:37:13 rasp hass[488]:     return await super().post(request, flow_id)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/http/data_validator.py", line 62, in wrapper
janv. 10 18:37:13 rasp hass[488]:     result = await method(view, request, *args, **kwargs)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/data_entry_flow.py", line 110, in post
janv. 10 18:37:13 rasp hass[488]:     result = await self._flow_mgr.async_configure(flow_id, data)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/data_entry_flow.py", line 252, in async_configure
janv. 10 18:37:13 rasp hass[488]:     result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/data_entry_flow.py", line 325, in _async_handle_step
janv. 10 18:37:13 rasp hass[488]:     result: FlowResult = await getattr(flow, method)(user_input)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/homeassistant/components/brother/config_flow.py", line 62, in async_step_user
janv. 10 18:37:13 rasp hass[488]:     await brother.async_update()
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/brother/__init__.py", line 99, in async_update
janv. 10 18:37:13 rasp hass[488]:     if not (raw_data := await self._get_data()):
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/brother/__init__.py", line 233, in _get_data
janv. 10 18:37:13 rasp hass[488]:     await self._init_device()
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/brother/__init__.py", line 303, in _init_device
janv. 10 18:37:13 rasp hass[488]:     errindication, errstatus, errindex, _ = await hlapi.getCmd(*request_args, *oids)
janv. 10 18:37:13 rasp hass[488]:   File "/usr/local/lib/python3.10/asyncio/coroutines.py", line 124, in coro
janv. 10 18:37:13 rasp hass[488]:     res = func(*args, **kw)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/pysnmp/hlapi/asyncio/cmdgen.py", line 151, in getCmd
janv. 10 18:37:13 rasp hass[488]:     addrName, paramsName = lcd.configure(
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/pysnmp/hlapi/lcd.py", line 91, in configure
janv. 10 18:37:13 rasp hass[488]:     transport = transportTarget.openClientMode()
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/pysnmp/hlapi/transport.py", line 53, in openClientMode
janv. 10 18:37:13 rasp hass[488]:     self.transport = self.protoTransport().openClientMode(self.iface)
janv. 10 18:37:13 rasp hass[488]:   File "/data/homeassistant/lib/python3.10/site-packages/pysnmp/carrier/asyncio/dgram/base.py", line 96, in openClientMode
janv. 10 18:37:13 rasp hass[488]:     raise error.CarrierError(';'.join(traceback.format_exception(*sys.exc_info())))
janv. 10 18:37:13 rasp hass[488]: pysnmp.carrier.error.CarrierError: Traceback (most recent call last):
janv. 10 18:37:13 rasp hass[488]: ;  File "/data/homeassistant/lib/python3.10/site-packages/pysnmp/carrier/asyncio/dgram/base.py", line 93, in openClientMode
janv. 10 18:37:13 rasp hass[488]:     self._lport = getattr(asyncio, 'async')(c)
janv. 10 18:37:13 rasp hass[488]: ;AttributeError: module 'asyncio' has no attribute 'async'
janv. 10 18:37:13 rasp hass[488]: caused by <class 'AttributeError'>: module 'asyncio' has no attribute 'async'

@antonc42
Copy link

@roumano If you are using v4.4.12 from pip, you may have to do a python3 -m pip install --force-reinstall git+https://github.com/antonc42/[email protected] (assuming you are using my branch). This is because the version number is the same and pip won't reinstall the same version by default.

It also might be that your Home Assistant is using a Python virtualenv or something rather than the system Python modules. Sorry, I'm not familiar with how Home Assistant does things. From the output above, it looks like something other than the standard system Python module location. Yours is /data/homeassistant/lib/python3.10/site-packages. You will have to figure out how to enter the proper virtual environment to remove/add the module.

@flaviut
Copy link

flaviut commented Jan 10, 2022 via email

@roumano
Copy link

roumano commented Jan 10, 2022

Forgot to restart HA, it's working after, sorry for the noise...

@lextm
Copy link

lextm commented Jan 19, 2023

Various forks (pysnmp/pysnmp or lextudio/pysnmp) have fixed this.

@lextm
Copy link

lextm commented Sep 2, 2024

Time to revisit this after closing #429.

Recent releases by my team (6.x/7.x) have fixed this. Please upgrade to them, https://docs.lextudio.com/pysnmp/upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants