简体   繁体   中英

heroku Connection timed out (Connection timed out)

Hello everyone I want to someone till me if what I 'am doing is correct or not what I 'am trying to do is deploying spring boot in heroku and getting date from python (flask) framework which I 'am running it locally in my device, everything is woking fine locally in my device but when try to run spring boot in heroku I 'am getting this error 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

and this error shows in heroku logs:

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)

My spring boot code:

 @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 "";
    }

And here's my flask code:

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")

Also when I run heroku server locally it's working fine as well.

have you already configured the gunicorn package to deploy on heroku?

pip3 install flask gunicorn

and create the Procfile file and add:

web: gunicorn wsgi:app

Follow the link to How to Deploy: https://dev.to/techparida/how-to-deploy-a-flask-app-on-heroku-heb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM