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

aiohttp.server message="Bad status line 'Invalid method encountered'" #73885

Closed
KitHubek opened this issue Jun 23, 2022 · 72 comments · Fixed by #131744
Closed

aiohttp.server message="Bad status line 'Invalid method encountered'" #73885

KitHubek opened this issue Jun 23, 2022 · 72 comments · Fixed by #131744

Comments

@KitHubek
Copy link

The problem

After upgrade to newest 2022.6.7 i see this error at logs

What version of Home Assistant Core has the issue?

2022.6.7

What was the last working version of Home Assistant Core?

i dont remember

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

Diagnostics information

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: 03:36:42 (3 occurrences)
Last logged: 08:20:30

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

@lubosjerabek
Copy link

lubosjerabek commented Jun 28, 2022

I have the same issue after upgrading my containerized HA from 2022.5.2 to 2022.6.7

Error I'm seeing:

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

This happens upon startup since the upgrade. Using old container fortunately worked okay

@tomhash2
Copy link

tomhash2 commented Jul 6, 2022

Not an issue in my case.

After searching on the internet I came to conclusion that one of my devices in LAN is trying to connect to :8123 port using HTTPS.

I've reviewed all phones and tablets and turned out it was my sons device.

This was coincidence that it happened after upgrade.

@Dutchstyler
Copy link

Having the same error and occors 18 times, but not every day:

Logger: aiohttp.server
Source: /usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py:405
First occurred: 2 augustus 2022 om 16:48:11 (18 occurrences)
Last logged: 05:36:10

Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.10/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'"

Running on RPI4 - core-2022.7.3 - Home Assistant OS 8.4

@vaibhav2912
Copy link

I see the same error accompanied by another one before it.

2022-08-13 06:41:11.153 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 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.BadHttpMessage: 400, message='Pause on PRI/Upgrade'

2022-08-13 06:45:03.774 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 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'"

I have changed IP address of my HA instance to test the possibility of the reason tomhash2 gave that some device is trying to connect to HA instance using HTTPS and port 8123. Since I still this these errors, the HTTPS and port 8123 is not the reason in my case.

@vaibhav2912
Copy link

vaibhav2912 commented Aug 13, 2022

I see the same error accompanied by another one before it.

2022-08-13 06:41:11.153 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 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.BadHttpMessage: 400, message='Pause on PRI/Upgrade'

2022-08-13 06:45:03.774 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 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'"

I have changed IP address of my HA instance to test the possibility of the reason tomhash2 gave that some device is trying to connect to HA instance using HTTPS and port 8123. Since I still this these errors, the HTTPS and port 8123 is not the reason in my case.

UPDATE:
I did grep for my IP address in the config directory and found one auth token that was using https on my old IP address:8123.

grep result:
.storage/auth:462: "client_id": "https://192.168.1.108:8123/"

I opened config/.storage/auth file, went to this auth entry, found the device ID and searched for that again in the config directory. It was from my Galaxy watch. I have removed the auth token now.

Might be helpful for people to search for devices using HTTPS for port 8123 to reach HA instance.

BUT, in my case, I didn't change the IP address on my watch after I changed my HA IP. So, the watch couldn't have pinged my new IP with HTTPS and port 8123. So the aiohttp errors I got today morning (posted in the quoted message) are definitely not from my watch pinging 8123 using HTTPS.

I will report back if I see the errors again.

@vaibhav2912
Copy link

I see the same error accompanied by another one before it.

2022-08-13 06:41:11.153 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 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.BadHttpMessage: 400, message='Pause on PRI/Upgrade'

2022-08-13 06:45:03.774 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 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'"

I have changed IP address of my HA instance to test the possibility of the reason tomhash2 gave that some device is trying to connect to HA instance using HTTPS and port 8123. Since I still this these errors, the HTTPS and port 8123 is not the reason in my case.

UPDATE: I did grep for my IP address in the config directory and found one auth token that was using https on my old IP address:8123.

grep result: .storage/auth:462: "client_id": "https://192.168.1.108:8123/"

I opened config/.storage/auth file, went to this auth entry, found the device ID and searched for that again in the config directory. It was from my Galaxy watch. I have removed the auth token now.

Might be helpful for people to search for devices using HTTPS for port 8123 to reach HA instance.

BUT, in my case, I didn't change the IP address on my watch after I changed my HA IP. So, the watch couldn't have pinged my new IP with HTTPS and port 8123. So the aiohttp errors I got today morning (posted in the quoted message) are definitely not from my watch pinging 8123 using HTTPS.

I will report back if I see the errors again.

Saw the same error messages again. So what I did above didn't solve it.

2022-08-13 23:33:53.827 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 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-08-13 23:33:55.044 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 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.BadHttpMessage: 400, message='Pause on PRI/Upgrade'

@controlcde
Copy link

Any progress on this issue? I´ve got the error more than once (see above).

Logger: aiohttp.server
Source: /usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py:405 
First occurred: 2:13:21 PM (959 occurrences) 
Last logged: 2:14:59 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/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'"

Is there I could do to present more details?

@rajalingamj175
Copy link

I'm facing same issue. Please help

Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: 2022-11-15 13:59:07.202 ERROR (MainThread) [aiohttp.server] Error handling request Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: Traceback (most recent call last): Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 334, in data_received Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: messages, upgraded, tail = self._request_parser.feed_data(data) Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'" Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: 2022-11-15 13:59:07.699 ERROR (MainThread) [aiohttp.server] Error handling request Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: Traceback (most recent call last): Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 334, in data_received Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: messages, upgraded, tail = self._request_parser.feed_data(data) Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'" Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: 2022-11-15 13:59:07.732 ERROR (MainThread) [aiohttp.server] Error handling request Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: Traceback (most recent call last): Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 334, in data_received Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: messages, upgraded, tail = self._request_parser.feed_data(data) Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'" Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: 2022-11-15 13:59:07.766 ERROR (MainThread) [aiohttp.server] Error handling request Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: Traceback (most recent call last): Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 334, in data_received Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: messages, upgraded, tail = self._request_parser.feed_data(data) Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'" Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: 2022-11-15 13:59:07.795 ERROR (MainThread) [aiohttp.server] Error handling request Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: Traceback (most recent call last): Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 334, in data_received Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: messages, upgraded, tail = self._request_parser.feed_data(data) Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'" Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: 2022-11-15 13:59:07.826 ERROR (MainThread) [aiohttp.server] Error handling request Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: Traceback (most recent call last): Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 334, in data_received Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: messages, upgraded, tail = self._request_parser.feed_data(data) Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data Nov 15 13:59:07 NUC11PAHi7 homeassistant[6196]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'"

@m-reiner
Copy link

Same issue here, any updates on this?

I have a feeling it relates back to Nginx, which I'm using to reverse-proxy to my HA instance. I don't have any issues (I don't think) from the app on iOS, but when using Firefox on my laptop it can take ages to load HA through the reverse proxy and I see the same errors others are reporting...

@baldus88
Copy link

Hi.

I have similar error in my case after update HA 2022.12.
My environment: HA Core (docker version).

This is the log:

2022-12-16 13:08:27.734 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 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'"

In log have 9 occurrences

Thanks

@GarnetSunset
Copy link

Same issue here for me!

Logger: aiohttp.server
Source: /usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py:405
First occurred: 11:43:34 AM (5 occurrences)
Last logged: 11:44:11 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/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'"

@fuzzybear62
Copy link

Same issue:

HA 2023.01.1

Logger: aiohttp.server
Source: /usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py:405
First occurred: 16:42:05 (1 occurrences)
Last logged: 16:42:05
Error handling request

Traceback (most recent call last):
File "/usr/local/lib/python3.10/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'"

@pkleingu
Copy link

pkleingu commented Jan 22, 2023

Same here:
2023-01-23 00:14:23.930 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 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'"

@jum0n
Copy link

jum0n commented Jan 28, 2023

Similar here, message is different:
Logger: aiohttp.server
Source: /usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py:405
First occurred: 3:22:08 PM (1 occurrences)
Last logged: 3:22:08 PM
Error handling request

Traceback (most recent call last):
File "/usr/local/lib/python3.10/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.BadHttpMessage: 400, message='Pause on PRI/Upgrade'

@MakStashkevich
Copy link

Same here:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 332, 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'"

@jocamane
Copy link

#87861

@cayco
Copy link

cayco commented Feb 13, 2023

Logger: aiohttp.server
Source: /usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py:405
First occurred: 12:21:51 (12175 occurrences)
Last logged: 19:25:40

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/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'"

@borez
Copy link

borez commented Feb 25, 2023

Getting the same issues, and have isolated it down to my iOS home companion app remote accessing the HA instance, via external URL. Accessing the HA instance via internal URL has no issues.

In my case, I am accessing it remotely via http (unsecured) via duckdns, and with my router port forwarding 8123 to the HA device.

@jocamane
Copy link

In my case, I am accessing it remotely via https (secured) via duckdns, and with my router port forwarding 8123 to the HA device

@borez
Copy link

borez commented Feb 26, 2023

To add on, I get the same error as long I’m using external URL functionality. Used an internal IP on the external URL section, via wifi.

@nodermann2
Copy link

Double-check the URL you're using in your request. Make sure it's correctly formatted and that there are no extra characters or spaces. Ensure the URL scheme (http/https) is correct for the API you're using. I had a similar problem, I specified the port to a URL, but it was not necessary.

@Vladimirlashuk
Copy link

I found out that such errors occur when the https://about.censys.io/ service sends requests like:
167.94.138.126 [28/Apr/2023:01:49:57 +0000] "GET / HTTP/1.1" 404 172 "-" "Mozilla/5.0 (compatible; CensysInspect/1.1; +https://about.censys. io/)"
On their official website, you can see from which ip addresses this happens and block them on the server->>
https://support.censys.io/hc/en-us/articles/360043177092-Opt-Out-of-Data-Collection

@jocamane
Copy link

I found out that such errors occur when the https://about.censys.io/ service sends requests like: 167.94.138.126 [28/Apr/2023:01:49:57 +0000] "GET / HTTP/1.1" 404 172 "-" "Mozilla/5.0 (compatible; CensysInspect/1.1; +https://about.censys. io/)" On their official website, you can see from which ip addresses this happens and block them on the server->> https://support.censys.io/hc/en-us/articles/360043177092-Opt-Out-of-Data-Collection

But I don't have censys service !!!

@mitag
Copy link

mitag commented Jun 10, 2023

Same here, using
NGINX Home Assistant SSL proxy 3.5.0
2023.6.1
Home Assistant OS 10.2

@benwainwright
Copy link

Same Problem here

@Coder84619
Copy link

Coder84619 commented Jun 25, 2023

I did a fresh install of HAOS 10.3 with 2023.6 and then immediately installed the Let's Encrypt add-on and issued a wildcard SSL cert. When I restart HA and attempt to access HA via HTTPS it fails, and I see the error in this thread in the log.

@hkphh
Copy link

hkphh commented Jun 29, 2023

guys, have a same problem
my HA works in docker
by typing docker logs homeassistant i see:

2023-06-30 00:41:32.471 ERROR (MainThread) [homeassistant.components.http.forwarded] Received X-Forwarded-For header from an untrusted proxy 172.28.0.1

the ip 172.28.0.1 is my docker network. I just added this net to trusted proxy and it all work fine now.
I also usng https with duckdns. Hope my solution will help you

My nginx.conf with reverse proxy on it

server {
server_name homeassistant.bla.bla;
proxy_ssl_server_name on;
location / {
proxy_ssl_name $host;
proxy_pass http://localhost:8123; #HA is on 80 port, docker listen 8123
proxy_set_header Host $host;
proxy_pass_header Authorization;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/homeassistant.bla.bla/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/homeassistant.bla.bla/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
if ($host = homeassistant.bla.bla) {
return 301 http://$host:8123$request_uri;
} # managed by Certbot
server_name homeassistant.bla.bla;
listen 80;
return 404; # managed by Certbot
}

@rynewang
Copy link

rynewang commented Jul 3, 2023

This may be related to this issue: aio-libs/aiohttp#7208

Basically, if the request does not set content-length, aiohttp server returns 400 with Invalid method encountered.

@cheadrian
Copy link

With regards to the first error, it's possible that your webserver is mistakenly trying to speak unencrypted HTTP to a request that came in on port 443 (HTTPS).

Source

If you have a Home Assistant instance that doesn't integrate the SSL certificate in the main configuration and you (or an integration, plugin, etc.) are trying to access the encrypted version of the API / dashboard, this error is going to appear.

Check the http configuration.

http:
  server_port: 8123
  ssl_certificate: /etc/letsencrypt/live/YOUR_DDNS_URL.com/fullchain.pem
  ssl_key: /etc/letsencrypt/live/YOUR_DDNS_URL.com/privkey.pem
  cors_allowed_origins:
    - https://google.com
    - https://www.home-assistant.io
    - https://cast.home-assistant.io
    - cast.home-assistant.io
    - https://YOUR_DDNS_URL.com:8123

I use Home Assistant like this without trouble, over TLS / SSL.

@ur7x
Copy link

ur7x commented Dec 21, 2023

cors_allowed_origins:
- https://google.com

A couple of questions

The DDNS_URL is my DuckDNS domain, right? and

Why am I allowing google?

EDIT

This did not solve the error for me... Still getting the error

@ehallq
Copy link

ehallq commented Dec 21, 2023

1, "method": "mining.subscribe", "params": ["cpuminer/2.5.1"]}'\n ^'

I got this exact same log in my home assistant aswell. My home assistant frontend crashes very often now. Anyone know what this is? Is there a miner on my device or are there just someone trying to make sim random api call to my server where this line is included?

@rvalitov
Copy link

rvalitov commented Jan 4, 2024

I had this issue. It happened because HA was working in HTTP mode and the proxy tried to access it in HTTPS mode. A proper HA configuration to work in HTTPS mode solved this issue.

@ur7x
Copy link

ur7x commented Jan 5, 2024

Any link/tip on how you converted HA into HTTPS mode?
My HA instance only accepts HTTPS access and I get this error a few times a day,

@cheadrian
Copy link

@ur7x you are not running HA through a proxy, like Nginx, Apache, correct?
Otherwise, this should be enough.

Maybe there's still an integration with still uses unsecure connection to a server?

@rvalitov
Copy link

rvalitov commented Jan 5, 2024

Exactly. If some person, device, service or scanner accidentally or intentionally tries to access your HA with a different HTTP(S) protocol than expected, you will get this kind of error in log anyway.

@ur7x
Copy link

ur7x commented Jan 6, 2024

@ur7x you are not running HA through a proxy, like Nginx, Apache, correct? Otherwise, this should be enough.

Maybe there's still an integration with still uses unsecure connection to a server?

I use DuckDNS to get a certficate and external domain. But no proxy.

I tried your config change and it made no change to my errors.

@cheadrian
Copy link

Don't know much about DuckDNS integration, but it might act like a reverse proxy. Try with other DNS provider with standalone tools for updating the IP, like NO-IP and get a certificate with certbot.
I have DNS configured to be updated by the router, and another one by the IPS.

@rvalitov
Copy link

rvalitov commented Jan 6, 2024

@ur7x you can stay on DuckDDNS and just test your HA with wget or curl using different HTTP(S) method to trigger this error and confirm that it happens because of this...

@jocamane
Copy link

jocamane commented Jan 6, 2024

@ur7x you can stay on DuckDDNS and just test your HA with wget or curl using different HTTP(S) method to trigger this error and confirm that it happens because of this...

and how to do this? you can help? thanks

@ur7x
Copy link

ur7x commented Jan 7, 2024

@ur7x you can stay on DuckDDNS and just test your HA with wget or curl using different HTTP(S) method to trigger this error and confirm that it happens because of this...

Thanks I tried that...
I installed wget on my PC and tried to use it to down load a known backup file from the backup directory.. first using my internal HTTPS address (https://192.168.X.Y:8123) . wget failed with a certificate error...

Then it tried with the same address, just http this time.
wget managed to connect but HA refused access to the file..

Then I tried http with my duckdns domain name...
wget connected and succeeded.

Then I tried https with my duckdns domain name..
wget connected and failed to find the file.?! (404 error)

all surprising results.

Even more surprising NONE of the four wget commands triggered the aiohttp error.

@cheadrian
Copy link

Certificate error is correct as the certificate is issued by domain name, so you can't use it for LAN connection without ignoring some security policies.

@ur7x
Copy link

ur7x commented Jan 9, 2024

Certificate error is correct as the certificate is issued by domain name, so you can't use it for LAN connection without ignoring some security policies.

Understood. But that test also produced ZERO aiohttp errors... so something else is causing them .

@rvalitov
Copy link

You can ignore SSL errors with wget https://redfern.me/skipping-certificate-checks-with-wget/

@issue-triage-workflows
Copy link

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.

@Stoffl17
Copy link

The topic is still present. In my case I have meanwhile the feeling that it comes from IOS mobile app.
Sometime you can find behind "Invalid method encountered:" something which looks similar to an IP-Address. The same IP-Address can be found in the auth-file in ".storage" which guides me to the mentioned assumption. In other cases the info behind "Invalid method encountered:" is a little bit strange: b'\x16\x03\x01'

I get this type of message 1-2 times a day.

@jocamane
Copy link

me too

@gruberdev
Copy link

There should be an option to disable SSL verification when establishing connections to the server. I am using it through Wireguard, which ensures that all my data remains encrypted, even when transmitted over HTTP.

It would be beneficial to include an advanced configuration setting that allows experienced users to override security settings.

Since I operate a k8s cluster where certificates are generated automatically, it's impractical to update the container configuration files with a new certificate each time one is generated.

@issue-triage-workflows
Copy link

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.

@Stoffl17
Copy link

Topic shall not be closed as it is still present.
At least an information would be helpfull, how to debug "who the guilty guy is", which leads to that bad status line.

@Bohreromir
Copy link

not stale

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.