Reputation: 511
I'm building a Rest API with Flask. The API uses data from Elasticsearch that is running on localhost.
It is possible to send an HTTP request from Flask route to localhost?
Something like this:
@flashlog.route('/checkelasticisup')
def check_elastic_is_up():
res = requests.get('http://localhost:9200/')
return jsonify({'message': res.text})
I want to return to the client the Elasticsearch response that you get when you send GET request to localhost:9200:
{
"name": "wEV_Spx",
"cluster_name": "elasticsearch",
"cluster_uuid": "dbPLLgYLRO69iYuT_pp4WA",
"version": {
"number": "6.3.0",
"build_flavor": "default",
"build_type": "deb",
"build_hash": "424e937",
"build_date": "2018-06-11T23:38:03.357887Z",
"build_snapshot": false,
"lucene_version": "7.3.1",
"minimum_wire_compatibility_version": "5.6.0",
"minimum_index_compatibility_version": "5.0.0"
},
"tagline": "You Know, for Search"
}
For now, I'm getting:
Network Error (dns_unresolved_hostname)
<HTML><HEAD>
<TITLE>Network Error</TITLE>
</HEAD>
<BODY>
<FONT face="Helvetica">
<big><strong></strong></big><BR>
</FONT>
<blockquote>
<TABLE border=0 cellPadding=1 width="80%">
<TR><TD>
<FONT face="Helvetica">
<big>Network Error (dns_unresolved_hostname)</big>
<BR>
<BR>
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
Your requested host "localhost" could not be resolved by DNS.
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica" SIZE=2>
<BR>
For assistance, contact your network support team.
</FONT>
</TD></TR>
</TABLE>
</blockquote>
</FONT>
</BODY></HTML>
How can I send an HTTP request to localhost (I'm using Ubuntu 18.04 LTS)?
Thanks!!
Upvotes: 2
Views: 38468
Reputation: 511
The problem was with my proxy configuration. Didn't configure the correct IP's to ignore. After i added localhost, 127.0.0.1/8 and ::1 to the ignore host field in network settings om my Ubuntu machine, everything works.
Upvotes: 3
Reputation: 195
As @Metalik said, you must replace localhost
with 127.0.0.1
for this to be able to work.
Upvotes: 4