【问题标题】:Invalid HTTP request received with Fast API使用 Fast API 接收到的 HTTP 请求无效
【发布时间】:2022-01-15 23:14:57
【问题描述】:

我有一个 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

另外,如果我通过 Postman 提出请求,一切都会再次正常运行。这是我的主机的问题,还是我缺少一些 uvicorn 配置?

【问题讨论】:

    标签: reactjs fastapi uvicorn


    【解决方案1】:

    当微服务不支持 HTTPS 时,将 urlhttps 更改为 http

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

    【讨论】:

    • 哪个网址?你是说我的整个前端应用?
    • 我说的是远程主机
    • 远程主机已经是http了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 2023-03-20
    相关资源
    最近更新 更多