[英]heroku Connection timed out (Connection timed out)
大家好,如果我正在做的事情正确与否,我想要有人直到我正在尝试做的是在 heroku 中部署 spring 引导并从 python 本地运行它的设备框架中获取日期,在我的设备中本地一切正常,但是当尝试在 heroku 中运行 spring 启动时,我at=error code=H12 desc="Request timeout" method=GET path="/hi" host=java-be.herokuapp.com request_id=454eaa9f-b9e3-4c03-9e7d-4bf5b6c450a9 fwd="5.45.134.17" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http
并且此错误显示在 heroku 日志中:
org.springframework.web.client.ResourceAccessException:
I/O error on GET request for "http://192.168.43.142:5000/":
Connection timed out (Connection timed out); nested exception
is java.net.ConnectException:
Connection timed out (Connection timed out)
我的 spring 启动代码:
@GetMapping("/")
String home() throws URISyntaxException {
try {
RestTemplate restTemplate = new RestTemplate();
String url = "http://192.168.43.142:5000/"; // flask local host url
String helloWorld= restTemplate.getForObject(url, String.class);
SimpleClientHttpRequestFactory rf =(SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(1000);
rf.setConnectTimeout(1000);
return helloWorld;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
这是我的 flask 代码:
from flask import Flask
from waitress import serve
app = Flask(__name__)
@app.route('/', methods=['GET'])
def home():
return "hello world"
if __name__ == '__main__':
try:
from waitress import serve
serve(app, host="0.0.0.0", port="5000")
except:
print("unexpected error")
此外,当我在本地运行 heroku 服务器时,它也运行良好。
您是否已经配置了 Gunicorn package 以部署在 heroku 上?
pip3 install flask gunicorn
并创建 Procfile 文件并添加:
web: gunicorn wsgi:app
按照如何部署的链接: https://dev.to/techparida/how-to-deploy-a-flask-app-on-heroku-heb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.