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
71.81k stars 30.06k forks source link

aiohttp.server Error #63162

Closed MNLFDF closed 1 year ago

MNLFDF commented 2 years ago

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

spoof54 commented 2 years ago

Hi, Same problem here ! Get this too from a fresh install with no config !

2022-01-03 08:46:45 ERROR (MainThread) [aiohttp.server] 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'"
2022-01-03 08:46:48 WARNING (MainThread) [homeassistant.components.http.ban] Login attempt or request with invalid authentication from Z-Fold3-de-Steven.home (192.168.1.76). (Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-F926B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/16.0 Chrome/92.0.4515.166 Mobile Safari/537.36)

This happened from Samsung Internet on my Fold3, Safari on my iPad. But the connection is ok when I'm using Firefox on my PC or the Android HomeAssistant App..

jag624 commented 2 years ago

Same issue - fresh Docker install:

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'"

spoof54 commented 2 years ago

Just tried to install Firefox on my Samsung Fold3, the connection to HASS is ok with Firefox. It's a User Agent problem ?

spoof54 commented 2 years ago

I managed to fix the problem by installing https access with the Nginx Proxy Manager addon. It now works from my Samsung with Samsung Internet not my old iPad but it looks like it's another problem (I cannot enter the password correctly, it takes just 1 on 2 character).

SiteBooster commented 2 years ago

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

spoof54 commented 2 years ago

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

Did your HomeAssistant updated ?

Maybe an error with your internal or external URI in the settings ?

KitHubek commented 2 years ago

the same problem here. After add ssl and remote connection on chrome dont work, m edge too. Samsung browser working ok Problem is only with local ip address connection. Remote working ok.

Problem is at HA appwith local connection

log:

Logger: aiohttp.server
Source: /usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py:405
First occurred: 8 January 2022, 23:56:02 (11 occurrences)
Last logged: 00:07:17

Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1183, in _sendfile_fallback
    read = await self.run_in_executor(None, file.readinto, view)
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 514, in start
    resp, reset = await task
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 460, in _handle_request
    reset = await self.finish_response(request, resp, start_time)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 613, in finish_response
    await prepare_meth(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_fileresponse.py", line 286, in prepare
    return await self._sendfile(request, fobj, offset, count)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_fileresponse.py", line 99, in _sendfile
    await loop.sendfile(transport, fobj, offset, count)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1162, in sendfile
    return await self._sendfile_fallback(transport, file,
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1192, in _sendfile_fallback
    await proto.restore()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 263, in restore
    self._transport.resume_reading()
  File "/usr/local/lib/python3.9/asyncio/sslproto.py", line 343, in resume_reading
    self._ssl_protocol._transport.resume_reading()
AttributeError: 'NoneType' object has no attribute 'resume_reading'

And all refresh and new login via local IP logs login failed with:

Logger: homeassistant.components.http.ban
Source: components/http/ban.py:124
Integration: HTTP (documentation, issues)
First occurred: 8 January 2022, 23:59:28 (4 occurrences)
Last logged: 00:07:16

Login attempt or request with invalid authentication from 192.168.0.3 (192.168.0.3). (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36)
UPS90 commented 2 years ago

Same problem here. The problem started when opening the devices and deleted the Xiaomi plugin but yesterday it was the same with the Shelly plugin. Reboot container solved temporarily

System: RPI 4 -> Docker Home assistant

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'"

emphasize commented 2 years ago

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)

joelphillipsABHS commented 2 years ago

Also having the same issue. I have been using duckdns and port forwarding and all working fine with SSL. When I have activated Nginx proxy manager and use: trusted_proxies:

Mariusthvdb commented 2 years ago

not sure if this is relevant for OP's issue, but when changing protocol, (internal http: / external https: ) be sure to check all references you had to https:// before.

see: https://github.com/NabuCasa/hass-nabucasa/issues/311#issuecomment-1024868556

I had that exact issue, checked all packages, but had forgotten one of add-ons used https internally....

onichan88 commented 2 years ago

I have the same problem with duckdns and nginx ssl proxy, and with asus router with lets encrypt and nginx ssl proxy. I hope it will be easy to solve...

Madelinot commented 2 years ago

Same issue here. I was using DuckDNS and it was all working. I tried both the NGINX HA Assistant Proxy and the NGINX Proxy Manager add-ons and they don't work, giving me this error in the logs. I tried re-installing the add-ons too. The add-ons themselves seems to work, but they don't serve HTTPS as expected. Error paste:

2022-03-03 07:39:38 ERROR (MainThread) [aiohttp.server] 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'"
2022-03-03 07:39:38 ERROR (MainThread) [aiohttp.server] Error handling request

If I re-enable this in my configuration.yaml file, the errors disappear from the log and I get the SSL cert without issues:

http:
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

I did add this as well:

  use_x_forwarded_for: true
  trusted_proxies:
    - 172.16.0.0/12
    - 127.0.0.0/8

Changed the trusted proxies combination, tried 192.168.1.0/24 and I even tried 0.0.0.0/0; same results. The logs gets exactly 14 errors as above every time I try to access the site using HTTPS. The certificate does not get transferred either.

I'm really at lost here. Nothing I tried worked. Could this be related: https://github.com/aio-libs/aiohttp/issues/6566 ?

I think I will just bite the bullet and try a complete fresh install... :-( But I may end up with the same situation.

budcalloway commented 2 years ago

Same as Madelino for me If I remove the

http:
   ssl_certificate: /ssl/fullchain.pem
   ssl_key: /ssl/privkey.pem

in the configuration.yaml, I end up with the same SSL error. I am using DuckDNS and NGINX Home Assistant SSL proxy

It happens when I am accessing HA through http://local.IP:8123 (no https for local access). This error does not occure when I use the external adress from duckdns

For me, I think that I'll live with this error. Everything's fine

Madelinot commented 2 years ago

Alright, here is an update. I have HASS installed on a RPi 4. I took the SD card out and reinstalled a new one with HASS on it. Completely fresh install, and updated. I proceeded to set it up and the first thing I did was install MariaDB and the Nginx Proxy Manager. I added the http: section in configuration.yaml with trusted proxies 0.0.0.0/0. Nothing else yet. I configured Nginx with the hosts I need and I was able to get my certificates for them. But I am still getting the exact same errors in the log. I'm starting to think it's not related at all to HomeAssistant, but I have no clue what else it could be.

Another update: I replaced my home router: no change (as expected).

lpt2007 commented 2 years ago

Same error here. Anyone find solution?

Madelinot commented 2 years ago

I found it. It was simply a port forwarding misconfiguration on my router in my case. Duh! Makes me mad I could not figure this out before now.

guyoverhere commented 2 years ago

I found it. It was simply a port forwarding misconfiguration on my router in my case. Duh! Makes me mad I could not figure this out before now.

What was your port forwarding error? I'm having the exact same issue as you were.

Madelinot commented 2 years ago

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

guyoverhere commented 2 years ago

Thanks for replying. I figured out I was doing the same thing before you replied. It was probably due to my earlier DynuDNS setup.

Merril-r commented 2 years ago

I am getting this error on a clean install of 2022.5.1. No addons added. Just stock standard install running on a VM

SVG62 commented 2 years ago

The following is all I needed to do configuration.yaml , and a reboot of course.

http: use_x_forwarded_for: true trusted_proxies:

duncanch89 commented 2 years ago

I turned off port forwarding from 8123 to 8123 and it resolved it for me. I still have the ports forwarded for Swag/nginx, but the port is already specified in the Swag config file so I guess creating a forward rule for 8123 was causing issues

7ooL commented 2 years ago

I was seeing same error.

I use cloudflare to povide DNS, the issue for me was it was blocking based on a broswer integrity check, turning this off allowed Amazon Alexa to link to my Home Assistant. Browser Integrity Check Evaluate HTTP headers from your visitors browser for threats. If a threat is found a block page will be delivered.

delta010 commented 2 years ago

same error for me after using the Nginx addon. before that, I was using normal port forwarding to assess HA from outside . also, I think one of the reasons for the error is some external devices trying to connect HA using the old URL(https://192.168.1.2) or in my case, I am not using port 443 on Nginx I am using port 9245

pedropinn commented 2 years ago

Same issue here. I'm not using Ngnix, only DuckDNS and it's working. I can't open my add-ons, but they are runing on background. Node-red and Zigbee2mqtt works fine but I can't saw web UI.

ronniebee commented 1 year ago

Any update on this issue? Having the same problem.

BramVR commented 1 year ago

Same issue here when using DuckDNS

BramVR commented 1 year ago

I managed to fix mine by setting the port forwarding protocol to TCP on my router.

drzacek commented 1 year ago

Happened to me to. I upgraded to newest python (3.10) and installed homeassistant in new venv. Then I deleted all config dir to start fresh. This error kept comming (I saw new timestamt with systemctl status home-assistant) every time I tried refreshing the page - which was stuck in loading.

It loaded properly when I changed the https://[local_ip]:8123 to http://[local_ip]:8123

But this can't be the solution

pandaedward commented 1 year ago

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.

Faser93 commented 1 year ago

This is how it looks like, if you point to home assisat using https you need to have ssl certificates on your machine in configuration because https needs that. There are 2 options: Internet ->HTTPS -> proxy -> HTTPS -> home assistant(using certs and https) Internet ->HTTPS ->proxy -> HTTP -> home assistant (doesn;t need certs) It depends on you which traffic you encrypt.

luky956 commented 1 year ago

Hi all, I fixed this problem on my installation. I still had the old port forwarding from external port xxx to internal port 8123. This was causing conflict in Caddy. Correcting with external port equal to internal port indicated on the Caddy configuration the problem has been solved.

I hope you find it useful

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.