question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: AES key must be either, 24, or 32 bytes lon 16g

See original GitHub issue

Environment: Sungrow Inverter SG8K-D with Wifi Adaptor. Raspi8 with Python 3.8. Port 502 accessible by scanning. Error: ValueError: AES key must be either, 24, or 32 bytes lon 16g

I have attempted to re-install and update all dependencies with no errors.

./solariot.py Load config sungrow-sh5k Load SungrowModbusTcpClient Connect Traceback (most recent call last): File “./solariot.py”, line 77, in <module> client.connect() File “/solariot/SungrowModbusTcpClient.py”, line 32, in connect self._getkey() File “/solariot/SungrowModbusTcpClient.py”, line 22, in _getkey self._aes_ecb = AES.new(self._key, AES.MODE_ECB) File “/usr/lib/python2.7/dist-packages/Crypto/Cipher/AES.py”, line 94, in new return AESCipher(key, *args, **kwargs) File “/usr/lib/python2.7/dist-packages/Crypto/Cipher/AES.py”, line 59, in init blockalgo.BlockAlgo.init(self, _AES, key, *args, **kwargs) File “/usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py”, line 141, in init self._cipher = factory.new(key, *args, **kwargs) ValueError: AES key must be either, 24, or 32 bytes lon 16g

`inverter_ip = “10.1.1.7” inverter_port = 502

Slave Defaults

Sungrow: 0x01

SMA: 3

slave = 0x01 model = “sungrow-sh5k” timeout = 3 scan_interval = 10

Optional:

dweepy_uuid = “random_solar_thing”

Optional:

influxdb_ip = “192.168.1.128” influxdb_port = 8086 influxdb_user = “user” influxdb_password = “password” influxdb_database = “inverter” influxdb_ssl = True influxdb_verify_ssl = False

Optional

mqtt_server = “192.168.1.128” mqtt_port = 1883 mqtt_topic = “inverter/stats” mqtt_username = “user” mqtt_password = “password” `

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
michael-robbinscommented, May 10, 2021

@meltaxa maybe we just close this off if @wombatvic isn’t responding?

1reaction
shannondpastocommented, May 3, 2021

Thanks @shannonpasto, that’s a great find. Would you mind sharing your sg3kd map? I’ll add it to repo.

Here it is. Sorry if the formatting didn’t work out properly

read_register = {
  "5003": "daily_power_yield_0.01", # Wh
  "5004": "total_power_yield_100",  # MWh
  "5008": "internal_temp_10",       # C
  "5011": "pv1_voltage_10",         # V
  "5012": "pv1_current_10",         # A
  "5013": "pv2_voltage_10",         # V
  "5014": "pv2_current_10",         # A
  "5017": "total_pv_power",         # W
  "5019": "grid_voltage_10",        # V
  "5022": "inverter_current_10",    # A
  "5031": "total_active_power",     # W
  "5036": "grid_frequency_10"      # Hz
}

holding_register = {
  "5000": "year",
  "5001": "month",
  "5002": "day",
  "5003": "hour",
  "5004": "minute",
  "5005": "second"
}

scan = """{
    "read": [
        {
            "start": "5000",
            "range": "100"
        },
        {
            "start": "5100",
            "range": "50"
        }
  ],
  "holding": [
    {
      "start": "4999",
      "range": "10"
    }
  ]
}"""

# Match Modbus registers to pvoutput api fields
# Reference: https://pvoutput.org/help/api_specification.html#add-status-service
pvoutput = {
  "Energy Generation": "daily_power_yield",
  "Power Generation": "total_active_power",
  "Temperature": "internal_temp",
  "Voltage": "grid_voltage"
}```
Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: AES key must be either 16, 24, or 32 bytes long
The AES constructor fails with the ValueError listed in the title. bkey32 is: b"['!', '%', 'F', '=', '-', ...
Read more >
AES key must be either 16, 24, or 32 bytes long · Issue #364
I just tried out the version 6 of tendenci in debug mode and it welcome me with this message. Probably due to this...
Read more >
ValueError: AES key must be either 16, 24, or 32 bytes long
I use AES encryption in Python; however, I have a problem about size of AES key. My encryption code is: from Crypto.Cipher import...
Read more >
ValueError: AES key must be either 16, 24, or 32 bytes long ...
The error is very clear. The key must be exactly of that size. os.urandom will return you the correct key. However this key...
Read more >
aes key must be either 16, 24, or 32 bytes long, valueerror: iv must ...
In case you are wondering, this key must be either 16, 24 or 32 bytes long. After that, we define an initialization vector...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found