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

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

Open
Janjre opened this issue Dec 28, 2023 · 2 comments
Open

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

Janjre opened this issue Dec 28, 2023 · 2 comments

Comments

@Janjre
Copy link

Janjre commented Dec 28, 2023

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
Copy link

lcosmin commented Jan 22, 2024

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
Copy link

lcosmin commented Jan 22, 2024

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...)

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

2 participants