gpt4 book ai didi

heroku - 达芙妮拒绝所有远程请求

转载 作者:行者123 更新时间:2023-12-02 03:06:00 25 4
gpt4 key购买 nike

我有一个项目,在该项目中我使用 channel 并且在本地一切正常,但是当我部署在 Heroku 上时,每次我尝试连接时都会收到 403。起初我以为问题出在 Heroku 上,因为我在本地对其进行了测试,甚至在本地使用了 Heroku 中的数据库和 redis 实例,一切正常。

但是,当我使用 ngrok 时打开一个公共(public)隧道到我的本地主机,我发现结果与 Heroku 中的相同。对于每个请求,我都会收到 403 并尝试调试它并没有多大帮助,因为事件循环有时会突然控制或者我会收到超时错误。除了一个在本地访问而另一个在远程访问之外,设置完全相同。这就是我开始达芙妮的方式: daphne weout.asgi:application --port 8000 --bind 0.0.0.0 -v 3.

我的库版本:

  • Django==2.0.7
  • channel ==2.2.0
  • channels-redis==2.4.0
  • 达芙妮==2.3.0

当 Daphne 的 versbosity 设置为最大时,这是我尝试连接时得到的结果:

Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,489 [asyncio] DEBUG: poll 101.195 ms took 0.023 ms: 1 events
Nov 22 07:16:34 weout-staging app/web.1 10.12.43.130:10299 - - [22/Nov/2019:15:16:33] "WSCONNECTING /api/v1/ws/" - -
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,513 [daphne.http_protocol] DEBUG: Upgraded connection ['10.x.x.x', 10299] to WebSocket
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,648 [asyncio] WARNING: Executing <Task pending coro=<AsyncConsumer.__call__() running at /app/.heroku/python/lib/python3.6/site-packages/channels/consumer.py:59> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fe01e6979d8>()] created at /app/.heroku/python/lib/python3.6/asyncio/base_events.py:276> created at /app/.heroku/python/lib/python3.6/site-packages/daphne/server.py:209> took 0.131 seconds
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,655 [daphne.server] INFO: failing WebSocket opening handshake ('Access denied')
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,656 [daphne.server] WARNING: dropping connection to peer tcp4:10.12.43.130:10299 with abort=False: Access denied
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,656 [daphne.ws_protocol] DEBUG: WebSocket ['10.x.x.x', 10299] rejected by application
Nov 22 07:16:34 weout-staging app/web.1 10.12.43.130:10299 - - [22/Nov/2019:15:16:33] "WSREJECT /api/v1/ws/" - -
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,660 [aioredis] DEBUG: Parsing Redis URI 'redis://xxxx@xxxxx'
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,660 [aioredis] DEBUG: Creating tcp connection to ('xxx.compute.amazonaws.com', 14059)
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,663 [asyncio] DEBUG: Get address info xxx, type=<SocketKind.SOCK_STREAM: 1>
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,667 [asyncio] DEBUG: Getting address info xxx.compute.amazonaws.com:14059, type=<SocketKind.SOCK_STREAM: 1> took 3.777 ms: [(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('x.x.x.x', 14059))]
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,669 [daphne.ws_protocol] DEBUG: WebSocket closed for ['10.x.x.x', 10299]
Nov 22 07:16:34 weout-staging app/web.1 10.12.43.130:10299 - - [22/Nov/2019:15:16:33] "WSDISCONNECT /api/v1/ws/" - -
Nov 22 07:16:34 weout-staging app/web.1 2019-11-22 15:16:33,671 [asyncio] DEBUG: connect <socket.socket fd=16, family=AddressFamily.AF_INET, type=2049, proto=6, laddr=('0.0.0.0', 0)> to ('x.x.x.x', 14059)

我使用 Daphne 为我的普通 Django View 和 websocket 消费者提供服务。 Django View 一切正常,所以只有在连接到消费者时才会出现问题

有没有人在远程访问Dapnhe时遇到类似的问题?起初我尝试用 uvicorn 搭配 gunicorn 但他们有一个 bug when the consumer is closed during the initial connection phase所以我换回了达芙妮

最佳答案

结果是 AllowedHostsOriginValidator !那肯定浪费了我很多时间。顺便说一下,对于没有 Origin header 的移动应用程序或其他来源的请求,您知道该中间件的行为如何吗?

无论如何我暂时删除它并且当前问题已解决

关于heroku - 达芙妮拒绝所有远程请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58997268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com