core: aiohttp.server Error

The problem

Getting error in system log Logger: aiohttp.server Source: /usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py:405

What version of Home Assistant Core has the issue?

2021.12.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: aiohttp.server
Source: /usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py:405 
First occurred: December 30, 2021, 18:50:01 (4 occurrences) 
Last logged: 07:18:26

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 334, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'"

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 34 (1 by maintainers)

Most upvoted comments

I was forwarding 443 to 8123 directly. I was in effect bypassing NGINX. Of course, I had to forward 443 to 443, then NGINX forwards 443 to 8123. So simple and obvious…

Same error happens when I use a Long-Lived Access Token to send a POST to /api/alexa/smart_home via public URL or internal IP of my Home Assistant instance running 2023.1.7:

023-01-31 12:18:44.192 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
resp = await request_handler(request)
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 81, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/alexa/smart_home_http.py", line 128, in post
message = await request.json()
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_request.py", line 663, in json
return loads(body)
File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I suspect the error is related to configuration in http: and those in Settings -> System -> Network -> Home Assistant URL

My set up ingress is proxied through Cloudflared:

http:
  ip_ban_enabled: true
  login_attempts_threshold: 3
  use_x_forwarded_for: true
  trusted_proxies:
    #home
    - 10.1.1.1/32
    #cloudflare ipv4
    - 103.21.244.0/22
    - 103.22.200.0/22
    - 103.31.4.0/22
    - 104.16.0.0/13
    - 104.24.0.0/14
    - 108.162.192.0/18
    - 131.0.72.0/22
    - 141.101.64.0/18
    - 162.158.0.0/15
    - 172.64.0.0/13
    - 172.30.33.0/24
    - 173.245.48.0/20
    - 188.114.96.0/20
    - 190.93.240.0/20
    - 197.234.240.0/22
    - 198.41.128.0/17

Home Assistant URL has the public facing Cloudflare hosted https URL in Internet field, with the internal IP:8123 in the Local Network.

Same error over here, but mine started showing after I added SSL via the Nginx Proxy Manager.

Saw this as i wanted to figure out if it is possible two serve up both http and https via NPM (which is not easily possible, at least not to my knownledge). I would suspect the configuration.yaml has no ssl_key/ssl_certificate entry or you transport a http to the home assistant instance which expects https (signified by the key) and therfor confusing aiohttp. (https has to be forced by npm)