连接到其python实例时出现Heroku错误:";“拒绝连接”;

连接到其python实例时出现Heroku错误:";“拒绝连接”;,python,curl,heroku,Python,Curl,Heroku,python成功启动,Heroku应用程序被卡在“监听端口5000”中,这应该是通过这个server.py: (...) parser.add_argument('-p', '--port', type=int, default=5000, help='port number') parser.add_argument('--debug', action='store_true', help='enable debug mode') args = parser.parse_args() if

python成功启动,Heroku应用程序被卡在“监听端口5000”中,这应该是通过这个
server.py

(...)
parser.add_argument('-p', '--port', type=int, default=5000, help='port number')
parser.add_argument('--debug', action='store_true', help='enable debug mode')
args = parser.parse_args()

if args.debug:
    app.debug = True

app.run(host='0.0.0.0')
这可以正常工作,heroku日志--tail显示应用程序按预期启动。heroku中的应用程序保持在“
上运行”http://0.0.0.0:33507/ (按CTRL+C退出)

然而,当像这样对我的heroku应用程序执行curl时,
curl-X POSThttps://APPNAME.herokuapp.com/search -H“Content-Type:application/json”-d'{“text”:“some_text”}'
应用程序会无限期地停止

当执行
curl-X POST时https://APPNAME.herokuapp.com:5000/search -H“Content Type:application/json”-d'{“text”:“some_text”}'
(注意我在url中添加了端口)我得到

(7) 无法连接到APPNAME.herokuapp.com端口5000:连接被拒绝

如果端口作为标志
-p 5000
传递,则相同

有人知道这到底是为什么吗


非常感谢

请记住,应用程序绑定到的端口与Heroku为您向internet公开的端口不同。Heroku为您监听http(端口80)和https(端口443)。因此,curl命令应该从URL中省略端口

Heroku的路由层充当应用程序的代理,它应该绑定通过
$port
环境变量提供的端口。但您不能直接连接到该端口(扩展而言,您不能通过HTTP以外的任何协议连接到应用程序)

此外,您发布的代码中还有一个小错误-
server.py
接受一个
--port
参数,但您没有将其传递给
run()
方法。您需要将其更改为
app.run(host='0.0.0.0',port=args.port)
。此外,确保
Procfile
web进程定义为
web:python server.py--port$port
,以便绑定到Heroku期望的端口(不保证端口5000)

希望有帮助