petretiandrea / plugp100

Work in progress implementation of tapo protocol in python.
GNU General Public License v3.0
71 stars 27 forks source link

AttributeError: module 'urllib3' has no attribute 'get_host' #169

Open Janjre opened 10 months ago

Janjre commented 10 months ago

When running the demo code, you get the error: AttributeError: module 'urllib3' has no attribute 'get_host' The offending line is: https://github.com/petretiandrea/plugp100/blob/b85f5ad1439bfdbf44cbd4bb979352e2babc63b2/plugp100/protocol/klap_protocol.py#L44C30-L44C38

urllib3 version is 2.1.0 plugp100 version is 4.0.1

lcosmin commented 9 months ago

I'm also seeing this with plugp100==4.0.3 in the home-assistant-tapo-p100 integration (v2.13.0).

024-01-22 11:06:45.719 DEBUG (MainThread) [plugp100.protocol.securepassthrough_transport] Will perform handshaking...
2024-01-22 11:06:45.719 DEBUG (MainThread) [plugp100.protocol.securepassthrough_transport] Generating keypair
2024-01-22 11:06:45.727 DEBUG (MainThread) [plugp100.protocol.securepassthrough_transport] Handshake params: {"key": "-----BEGIN PUBLIC KEY-----\nMIGfMA.....AAC6cQMwIDAQAB\n-----END PUBLIC KEY-----\n"}
2024-01-22 11:06:45.729 DEBUG (MainThread) [plugp100.protocol.securepassthrough_transport] Request {'method': 'handshake', 'params': {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSq.......6cQMwIDAQAB\n-----END PUBLIC KEY-----\n'}}
2024-01-22 11:06:45.742 DEBUG (MainThread) [plugp100.protocol.securepassthrough_transport] Device responded with: {'error_code': 1003}
2024-01-22 11:06:45.742 INFO (MainThread) [plugp100.api.tapo_client] Default protocol not working, fallback to KLAP ;)
2024-01-22 11:06:45.744 ERROR (MainThread) [custom_components.tapo.config_flow] Failed to setup cannot connect 
  File "/home/homeassistant/.homeassistant/custom_components/tapo/config_flow.py", line 192, in _get_first_data_from_api
    (await tapo_client.get_device_info())
  File "/srv/homeassistant/.venv/lib/python3.11/site-packages/plugp100/api/tapo_client.py", line 92, in get_device_info
  File "/srv/homeassistant/.venv/lib/python3.11/site-packages/plugp100/api/tapo_client.py", line 77, in execute_raw_request
  File "/srv/homeassistant/.venv/lib/python3.11/site-packages/plugp100/api/tapo_client.py", line 71, in _initialize_protocol_if_needed
  File "/srv/homeassistant/.venv/lib/python3.11/site-packages/plugp100/api/tapo_client.py", line 226, in _guess_protocol
  File "/srv/homeassistant/.venv/lib/python3.11/site-packages/plugp100/protocol/klap_protocol.py", line 44, in __init__
AttributeError: module 'urllib3' has no attribute 'get_host'
  File "/home/homeassistant/.homeassistant/custom_components/tapo/config_flow.py", line 119, in async_step_user
    device_data = await self._get_first_data_from_api(tapo_client)
  File "/home/homeassistant/.homeassistant/custom_components/tapo/config_flow.py", line 199, in _get_first_data_from_api
    raise CannotConnect from error
custom_components.tapo.errors.CannotConnect
lcosmin commented 9 months ago

The problem is here:

https://github.com/petretiandrea/plugp100/blob/main/plugp100/protocol/klap_protocol.py#L44

get_host() has been deprecated and it needs to be replaced.

Something like:

        self._host = urllib3.util.parse_url(self._base_url).host

fixed the HACS integration for me (but I'd add more error checking to it...)