使用 Fast API 收到无效的 HTTP 请求

Nea*_*atZ 3 reactjs fastapi uvicorn

我有一个 React 前端向运行 FastAPI 的 Discord.py 机器人发出请求。在我的测试环境中一切都很好,但是当我部署到远程主机时 uvicorn 抱怨

    WARNING:  Invalid HTTP request received.
Traceback (most recent call last):
  File "/home/container/uvicorn/protocols/http/h11_impl.py", line 136, in handle_events
    event = self.conn.next_event()
  File "/home/container/h11/_connection.py", line 443, in next_event
    exc._reraise_as_remote_protocol_error()
  File "/home/container/h11/_util.py", line 76, in _reraise_as_remote_protocol_error
    raise self
  File "/home/container/h11/_connection.py", line 425, in next_event
    event = self._extract_next_receive_event()
  File "/home/container/h11/_connection.py", line 367, in _extract_next_receive_event
    event = self._reader(self._receive_buffer)
  File "/home/container/h11/_readers.py", line 68, in maybe_read_from_IDLE_client
    raise LocalProtocolError("illegal request line")
h11._util.RemoteProtocolError: illegal request line
2022-01-15 22:59:11,310 - Invalid HTTP request received.
Traceback (most recent call last):
  File "/home/container/uvicorn/protocols/http/h11_impl.py", line 136, in handle_events
    event = self.conn.next_event()
  File "/home/container/h11/_connection.py", line 443, in next_event
    exc._reraise_as_remote_protocol_error()
  File "/home/container/h11/_util.py", line 76, in _reraise_as_remote_protocol_error
    raise self
  File "/home/container/h11/_connection.py", line 425, in next_event
    event = self._extract_next_receive_event()
  File "/home/container/h11/_connection.py", line 367, in _extract_next_receive_event
    event = self._reader(self._receive_buffer)
  File "/home/container/h11/_readers.py", line 68, in maybe_read_from_IDLE_client
    raise LocalProtocolError("illegal request line")
h11._util.RemoteProtocolError: illegal request line
Run Code Online (Sandbox Code Playgroud)

另外,如果我通过邮递员提出请求,一切都会恢复正常。这是我的主机的问题,还是我缺少的一些 uvicorn 配置的问题?

小智 10

当微服务不支持HTTPS时更改urlhttpshttp

例如: https: //stackoverflow.com/a/66442651/10850556