Byte encoding problem (or something similar)
Closed this issue · 2 comments
I was receiving the following error:
17-02-22 17:18:54 ERROR (MainThread) [homeassistant.bootstrap] Error during setup of component xiaomi
Traceback (most recent call last):
File "/srv/webapps/hass_env/lib/python3.5/site-packages/homeassistant/bootstrap.py", line 152, in _async_setup_component
None, component.setup, hass, config)
File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/srv/webapps/.homeassistant/custom_components/xiaomi.py", line 77, in setup
PY_XIAOMI_GATEWAY.discover_gateways()
File "/srv/webapps/.homeassistant/custom_components/xiaomi.py", line 167, in discover_gateways
self.gateways[ip_add] = XiaomiGateway(ip_add, port, sid, gateway_key, self._socket)
File "/srv/webapps/.homeassistant/custom_components/xiaomi.py", line 262, in __init__
if self._discover_devices():
File "/srv/webapps/.homeassistant/custom_components/xiaomi.py", line 271, in _discover_devices
self.update_key(resp["token"])
File "/srv/webapps/.homeassistant/custom_components/xiaomi.py", line 370, in update_key
encryptor = AES.new(bytes(self.key), AES.MODE_CBC, IV=init_vector)
TypeError: string argument without an encoding
And I somewhat "solved" it by changing the update_key
method with the following:
encryptor = AES.new(bytes(self.key, encoding="ascii"), AES.MODE_CBC, IV=init_vector)
ciphertext = encryptor.encrypt(bytes(token, encoding="ascii"))
but I, sincerely, have no idea what I'm doing. It seems that something has changed in some library since I don't know when...?
Sorry, I am in a rush. I will add more info if I discover anything. Feel free to ask me to change stuff or do some tests. Thanks and sorry!
I ran into the same issue when I upgraded my copy of the xiaomi component. I am guessing it is related to the removal of the versioned pycrypto requirement.
This pull request fixes it: #27
Good point on that. I'm using latest pycrypto (2.6.1) and that always work. I think rather than creating a fix for old version, i just define the version requirement for pycrypto.