keijack / python-eureka-client

A eureka client written in python. Support registering your python component to Eureka Server, as well as calling remote services by pulling the the Eureka registry.
MIT License
183 stars 43 forks source link

I/O error on GET request for "http://python-module-1/": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused) #52

Closed TEJESH closed 3 years ago

TEJESH commented 3 years ago

Hello I am getting error, while accessing flask microservice with spring boot micro service, and both are connected with Eureka server finely.

I/O error on GET request for "http://python-module-1/": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)

import json

from flask import Flask, Response, make_response, jsonify
from flask_eureka import Eureka
from flask_eureka.eureka import eureka_bp

import urllib

import py_eureka_client.eureka_client as eureka_client

app = Flask(__name__)

app.config.from_object(__name__)

app.register_blueprint(eureka_bp)

eureka = Eureka(app)
#eureka.register_service(name="python-module-1")

your_rest_server_port = 9090
eureka_client.init(eureka_server="http://localhost:8761/",
                                eureka_protocol="https",
                                app_name="python-module-1",
                                instance_port=your_rest_server_port)

@app.route('/')
def home():
    #result = {'status': 'UP'}
    return "Test case"

@app.route('/health')
def health():
    result = {'status': 'UP'}
    return Response(json.dumps(result), mimetype='application/json')

@app.route('/getUser')
def get_user():
    return Response(json.dumps({'username': 'python', 'password': 'python'}),
                    mimetype='application/json')

@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({'error': 'Not found'}), 404)

if __name__ == '__main__':
    app.run(debug=True)

Above service is registered with Eureka server, but while accessing the service, it gives the I/O error.

Below is spring app function::

@RequestMapping("/some")
public class CatalogResource {

    @Autowired
    private RestTemplate restTemplate;

    // @Autowired
    // WebClient.Builder webClientBuilder;

    @RequestMapping("/")
    public ResponseEntity<?> home(){
        System.out.println("Service1 Controller Called");
        ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://python-module-1/",
                String.class);
        return ResponseEntity.ok().body("Recieved Message: " + responseEntity.getBody());
        //return x;
    }

}

I tried to look everywhere, but couldn't find any solution on this problem. Please help me where I am getting wrong.

TEJESH commented 3 years ago

I even tried to change https://python-module-1/ instead of http://python-module-1/

still it gives me, below is full error. I included /error in my spring application too.

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Apr 25 20:41:35 EDT 2021
There was an unexpected error (type=Internal Server Error, status=500).
I/O error on GET request for "https://python-module-1/": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
keijack commented 3 years ago

Can you post the result in http://you-eureka-server/eureka/v2/apps ?

TEJESH commented 3 years ago

Screen Shot 2021-04-26 at 12 04 12 AM

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Apr 26 00:00:22 EDT 2021
There was an unexpected error (type=Not Found, status=404).
No message available

I put /error in my discovery server, still same error when I do http://localhost:8761/v2/apps

Screen Shot 2021-04-26 at 12 05 16 AM

TEJESH commented 3 years ago

I also tried to modify python file, when I put below code:

eureka.register_service(name="python-module-1")

right now, it is commented as above mentioned, that's why python file is running fine.

after adding the code, I get below error in my console:


  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_eureka/eurekaclient.py", line 129, in get_zones_from_dns
    for zone_url in list(self._get_zone_urls_from_dns('txt.%s.%s' % (self.region, self.eureka_domain_name)))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_eureka/eurekaclient.py", line 122, in _get_zone_urls_from_dns
    for zone in self._get_txt_records_from_dns(domain):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_eureka/eurekaclient.py", line 116, in _get_txt_records_from_dns
    records = dns.resolver.query(domain, 'TXT')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/dns/resolver.py", line 1132, in query
    raise_on_no_answer, source_port)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/dns/resolver.py", line 1051, in query
    raise NXDOMAIN(qnames=qnames_to_try, responses=nxdomain_responses)
dns.resolver.NXDOMAIN: None of DNS query names exist: txt.None.None., txt.None.None.home.
TEJESH commented 3 years ago

Hello @keijack,

Is there anything where I am going wrong?

TEJESH commented 3 years ago

I can easily work with two spring Microservices but it's giving

I/O error on GET request for "https://python-module-1/health/": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused) for flask microservice.

TEJESH commented 3 years ago

I figured it out, where I was going wrong.

I changed my init function and added below line:

instance_port=5000, instance_ip="127.0.0.1")