rpvelloso / Sungrow-Modbus

TCP Client for Sungrow Devices with encryption

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pycrypto broken under Python 3.10

tjhowse opened this issue · comments

This issue relates to this one: tjhowse/modbus4mqtt#37

2021-10-10 23:22:52 ERROR    Failed to poll modbus device, attempting to reconnect: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus4mqtt.py", line 87, in poll
    self._mb.poll()
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 71, in poll
    values = self._scan_value_range(table, group, self._scan_batching)
  File "/usr/local/lib/python3.10/site-packages/modbus4mqtt/modbus_interface.py", line 138, in _scan_value_range
    result = self._mb.read_input_registers(start, count, unit=0x01)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/common.py", line 125, in read_input_registers
    return self.execute(request)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 107, in execute
    if not self.connect():
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 54, in connect
    self._getkey()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 43, in _getkey
    self._setup()
  File "/usr/local/lib/python3.10/site-packages/SungrowModbusTcpClient/SungrowModbusTcpClient.py", line 23, in _setup
    self._aes_ecb = AES.new(self._key, AES.MODE_ECB)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 95, in new
    return AESCipher(key, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/AES.py", line 59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

I believe the core issue is that pycrypto has issues with Python 3.10. pycrypto hasn't been maintained since 2013. I think the solution to this may be migrating over to a maintained, or built-in, crypto library to get the functionality we need.

There's a good chance I'll be able to raise a PR for this issue within the next few days.

Would you be able to push up 0.1.6 to pypi when you are able? I'd like to be able to close out this issue.

Cheers!

just uploaded the changes to pypi. Can you verify if it's correct?

https://pypi.org/project/SungrowModbusTcpClient/0.1.6/

Yep! That's done the trick. Thanks!