我有一个本地运行的服务器。当我在AWS EC2上运行它并在8000端口上从外部发送请求时,我得到以下错误:
$ uvicorn sql_app.main:app --host="0.0.0.0" --port=8000
INFO: Started server process [9806]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
WARNING: Invalid HTTP request received.
Traceback (most recent call last):
File "/home/ec2-user/.local/lib/python3.7/site-packages/uvicorn/protocols/http/h11_impl.py", line 170, in handle_events
event = self.conn.next_event()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 443, in next_event
exc._reraise_as_remote_protocol_error()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_util.py", line 76, in _reraise_as_remote_protocol_error
raise self
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 425, in next_event
event = self._extract_next_receive_event()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 367, in _extract_next_receive_event
event = self._reader(self._receive_buffer)
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_readers.py", line 73, in maybe_read_from_IDLE_client
request_line_re, lines[0], "illegal request line: {!r}", lines[0]
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_util.py", line 88, in validate
raise LocalProtocolError(msg)
h11._util.RemoteProtocolError: illegal request line: bytearray(b'\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\x91\xa5\xe2Y\xf0\xa1\xdd\x1d+\x08\x1c\r\x15X\x1d@\x1e/\xb1N\x00\xb5\xe5\xec\xf3F\x1fm\x03\xa1{> \xa80\xb4\x14\x1aUs\xaa\xcd\xc3<s\xcd\xd1\x17\xdf3\x0e\xdbh\xd1c\x88}\x8c\x1f\xa5\x15\x9aa\x14I\x00 ')
WARNING: Invalid HTTP request received.
Traceback (most recent call last):
File "/home/ec2-user/.local/lib/python3.7/site-packages/uvicorn/protocols/http/h11_impl.py", line 170, in handle_events
event = self.conn.next_event()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 443, in next_event
exc._reraise_as_remote_protocol_error()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_util.py", line 76, in _reraise_as_remote_protocol_error
raise self
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 425, in next_event
event = self._extract_next_receive_event()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 367, in _extract_next_receive_event
event = self._reader(self._receive_buffer)
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_readers.py", line 68, in maybe_read_from_IDLE_client
raise LocalProtocolError("illegal request line")
h11._util.RemoteProtocolError: illegal request line
WARNING: Invalid HTTP request received.
Traceback (most recent call last):
File "/home/ec2-user/.local/lib/python3.7/site-packages/uvicorn/protocols/http/h11_impl.py", line 170, in handle_events
event = self.conn.next_event()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 443, in next_event
exc._reraise_as_remote_protocol_error()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_util.py", line 76, in _reraise_as_remote_protocol_error
raise self
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 425, in next_event
event = self._extract_next_receive_event()
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_connection.py", line 367, in _extract_next_receive_event
event = self._reader(self._receive_buffer)
File "/home/ec2-user/.local/lib/python3.7/site-packages/h11/_readers.py", line 68, in maybe_read_from_IDLE_client
raise LocalProtocolError("illegal request line")
h11._util.RemoteProtocolError: illegal request line
WARNING: Invalid HTTP request received.
如果您能告诉我如何在端口80上执行此操作,那将非常好。
尝试将默认超时更改为0。
启动uvicorn时使用此标志。
--timeout-keep-alive 0
我也有同样的问题,并通过添加HTTPS支持来解决它。我配置NGINX与LetsEncrypt证书。确保所使用的端口在安全组设置中处于打开状态。
我收到了同样的神秘警告:收到了无效的HTTP请求 错误,堆栈跟踪无效。我尝试了所有推荐的环境变量调整,但都没有成功(请参见FastAPI问题680,uvicorn问题441)。
我的问题是,当我调用我的FastAPI微服务时,我使用的是https
,而我的微服务没有HTTPS支持。我将url从https
更改为超文本传输协议
,它开始按预期工作。
请注意,如果您的服务需要HTTPS支持,您可以按照Ilgizar Murzakov的建议添加HTTPS支持。
我正在学习Fastapi,我正在localhost启动一个uvicorn服务器。每当出现错误/异常时,我都不会得到回溯。所有我得到的是: 所以,调试很困难,我正在试用python的日志模块 我还尝试过使用调试参数启动uvicorn
Uvicorn 是一个闪电般快速的ASGI服务器,基于uvloop和httptools构建。 直到最近,Python还没有为asyncio框架提供最小的低级服务器/应用程序接口。 ASGI规范填补了这一空白,意味着我们现在能够开始构建一个可用于所有asyncio框架的通用工具集。 ASGI帮助实现一个Python Web框架生态系统,该框架在与IO绑定的上下文中实现高吞吐量方面与Node和Go竞争
我承认我以前从未使用过。当我运行命令给出错误:
有人能帮我做这个吗? 我不知道错误是什么,也不知道我应该如何修复它。任何帮助都很感激
我正在尝试(失败)设置一个简单的FastAPI项目,并使用uvicorn运行它。这是我的代码: 这是我从终端运行的内容: 如你所见,我找不到404。原因可能是什么?一些与网络相关的东西,可能是防火墙/vpn阻止此连接或其他什么?我是新来的。提前谢谢!
问题内容: 我无法将JDBC连接到我的数据库,出现以下错误 问题答案: 根据stacktrace的说明,您使用的MySQL Connector / J版本使用的是Android不支持的功能(可能是named组)。解决方法是使用MySQL Connector / J的5.1.x版本而不是8.0.x版本。 但是,您不应使用Android应用程序中的JDBC。它是不安全的,并且通常无法直接连接到数据库。