home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.13k stars 31.12k forks source link

Rest sensor not working after installing Home Assistant Core #49782

Closed Christian-PK closed 3 years ago

Christian-PK commented 3 years ago

The problem

Hello, I have a problem with the rest sensor and httpx. When i set the configuration as below i get an attribute error. I have tried the home assistant docker image on another vm for test with the same configuration file and it works on the docker image. But i do not wish to run on docker.

I Installed Home Assistant Core on a fresh Ubuntu server live 20.04 last week. I tried to reinstall httpx with pip3 but same result. I have run apt update and apt upgrade. I tested i can access the url with curl

Any suggestions?

What is version of Home Assistant Core has the issue?

core-2021.4.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

sensor - rest

Link to integration documentation on our website

https://www.home-assistant.io/integrations/sensor.rest/

Example YAML snippet

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

sensor:
  - platform: rest
    resource: http://ip.jsontest.com
    name: External IP
    value_template: "{{ value_json.ip }}"

Anything in the logs that might be useful for us?

Logger: homeassistant.components.sensor
Source: components/rest/data.py:55
Integration: Sensor (documentation, issues)
First occurred: 20.20.00 (1 occurrences)
Last logged: 20.20.00

Error while setting up rest platform for sensor
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 205, in _async_setup_platform
    await asyncio.shield(task)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/rest/sensor.py", line 53, in async_setup_platform
    await rest.async_update()
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/rest/data.py", line 55, in async_update
    response = await self._async_client.request(
  File "/srv/homeassistant/lib/python3.8/site-packages/httpx/_client.py", line 1361, in request
    response = await self.send(
  File "/srv/homeassistant/lib/python3.8/site-packages/httpx/_client.py", line 1396, in send
    response = await self._send_handling_auth(
  File "/srv/homeassistant/lib/python3.8/site-packages/httpx/_client.py", line 1434, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/srv/homeassistant/lib/python3.8/site-packages/httpx/_client.py", line 1466, in _send_handling_redirects
    response = await self._send_single_request(request, timeout)
  File "/srv/homeassistant/lib/python3.8/site-packages/httpx/_client.py", line 1492, in _send_single_request
    (status_code, headers, stream, ext) = await transport.arequest(
  File "/srv/homeassistant/lib/python3.8/site-packages/httpx/_transports/default.py", line 169, in arequest
    return await self._pool.arequest(
AttributeError: 'AsyncConnectionPool' object has no attribute 'arequest'

Additional information

No response

probot-home-assistant[bot] commented 3 years ago

rest documentation rest source (message by IssueLinks)

elupus commented 3 years ago

First, you are using an old style config. Check dokumentation om how it should look.

Second i think you have wrong httpx version or one of its dependencies are wrong. Please remove the python virtual env you are running it in and recreate it. Running without a python env is not a working solution.

Christian-PK commented 3 years ago

if i run pip3 freeze then it shows i am running httpx 0.18.0, is that the right version?

I am not sure if i did it correct but to delete and create the virtual environment i ran the following commands: cd /srv/homeassistant

still the same result.

elupus commented 3 years ago

Nope looks lit it should be 0.17.1. so you have some component that pulls in 0.18.0

Christian-PK commented 3 years ago

So i changed to 0.17.1 but still no difference

(homeassistant) ha@ha:/srv/homeassistant$ pip3 list Package Version


acme 1.12.0 aiodiscover 1.3.4 aiohomekit 0.2.61 aiohttp 3.7.4.post0 aiohttp-cors 0.7.0 aiohue 2.1.0 appdirs 1.4.4 astral 1.10.1 async-dns 1.1.10 async-timeout 3.0.1 async-upnp-client 0.16.0 atomicwrites 1.4.0 attrs 20.3.0 awesomeversion 21.2.3 bcrypt 3.1.7 boto3 1.17.56 botocore 1.20.56 cached-property 1.5.2 casttube 0.2.1 certifi 2020.12.5 cffi 1.14.5 chardet 4.0.0 ciso8601 2.1.3 click 7.1.2 cryptography 3.3.2 deepmerge 0.3.0 defusedxml 0.6.0 distro 1.5.0 ecdsa 0.14.1 emoji 1.2.0 envs 1.3 gTTS 2.2.2 h11 0.12.0 ha-ffmpeg 3.0.2 hass-nabucasa 0.42.0 home-assistant-frontend 20210407.3 homeassistant 2021.4.6 homeconnect 0.6.3 httpcore 0.13.0 httpx 0.17.1 idna 2.10 ifaddr 0.1.7 isodate 0.6.0 Jinja2 2.11.3 jmespath 0.10.0 josepy 1.8.0 jsonpath 0.82 lxml 4.6.3 MarkupSafe 1.1.1 multidict 5.1.0 mutagen 1.45.1 netdisco 2.8.2 netifaces 0.10.9 oauthlib 3.1.0 onvif-zeep-async 1.0.0 Pillow 8.1.2 pip 20.0.2 pkg-resources 0.0.0 PlexAPI 4.5.1 plexauth 0.0.6 plexwebsocket 0.0.13 protobuf 3.15.8 pyasn1 0.4.8 pybotvac 0.0.20 PyChromecast 9.1.2 pycognito 0.1.5 pycparser 2.20 pyipp 0.11.0 PyJWT 1.7.1 PyMetno 0.8.2 PyNaCl 1.3.0 pyOpenSSL 20.0.1 pyotp 2.3.0 PyQRCode 1.2.1 pyRFC3339 1.1 pyroute2 0.5.18 python-dateutil 2.8.1 python-didl-lite 1.2.6 python-jose 3.2.0 python-slugify 4.0.1 pytz 2021.1 PyYAML 5.4.1 requests 2.25.1 requests-file 1.5.1 requests-oauthlib 1.3.0 requests-toolbelt 0.9.1 rfc3986 1.4.0 rsa 4.7.2 ruamel.yaml 0.15.100 s3transfer 0.4.2 scapy 2.4.4 setuptools 44.0.0 six 1.15.0 sniffio 1.2.0 snitun 0.20 spotipy 2.18.0 SQLAlchemy 1.3.23 text-unidecode 1.3 typing-extensions 3.7.4.3 urllib3 1.26.4 voluptuous 0.12.1 voluptuous-serialize 2.4.0 wheel 0.36.2 WSDiscovery 2.0.0 xmltodict 0.12.0 yarl 1.6.3 zeep 4.0.0 zeroconf 0.29.0

elupus commented 3 years ago

Have you fixed the config?

Christian-PK commented 3 years ago

Is it the specific sensor or the hole configuration.yaml. I can not see any difference in the documentation and my files.

elupus commented 3 years ago

Check the rest sensor documentstion linked above.

You have the config under: sensor/platform: rest. It should now be under rest/sensor.

bdraco commented 3 years ago

It looks like your httpcore version is too new to use with 0.17.1

https://github.com/encode/httpcore/releases

Downgrade httpcore to 0.12.3

bdraco commented 3 years ago

I tested httpx 0.18.0 with httpcore 0.13.0 and everything worked with rest.

I opened a PR to bump httpx to 0.18.0 here: https://github.com/home-assistant/core/pull/49805

Christian-PK commented 3 years ago

Changing the config did not change anything still same error

Configure a default setup of Home Assistant (frontend, api, etc)

default_config:

Text to speech

tts:

group: !include groups.yaml automation: !include automations.yaml script: !include scripts.yaml scene: !include scenes.yaml

rest:

I will try downgrade httpcore

Christian-PK commented 3 years ago

I destroyed the packagedependencies. So i deleted /srv/homeassistant and installed again, and now i works. Unfortunatley we will never know what the problem was.

Thanks a lot for you help.