2017-02-10 5 views
2

Ich bin mit Flash in den lokalen Host (http://localhost:5000) und versuchen, Python-Anfragen zu verwenden json Ergebnis von ElasticsearchPython localhost Anfrage auf gleiche localhost mit anderen Port

Hier ist mein Code

@app.route('/test') 
def TestElasticsearch(): 
    url = "http://localhost:9200/customer/_search?q=James&size=5" 
    r = requests.get(url) 
    print r 
    return r.text 

zu beantragen, wenn ich greife auf http://localhost:5000/test über google chrome, gibt es

ConnectionError: HTTPConnectionPool(host='localhost', port=9200): Max retries exceeded with url: /customer/_search?q=James&size=5 (Caused by <class 'socket.error'>: [Errno 111] Connection refused) 

Bitte beachte, dass ich versucht habe, http://localhost:9200/customer/_search?q=James&size=5 via google c Zugriff hrome und es funktioniert.

mir herauszufinden, das Problem Bitte helfen Sie statt localhost

+0

versuchen 127.0.0.1 verwenden. –

Antwort

0
Try: 

@app.route('/test') 
def TestElasticsearch(): 
    import urllib 
    url = 'http://localhost:9200/customer/_search?q=James&size=5' 
    # GET is the default action 
    response = urllib.urlopen(url) 
    # Output from the GET assuming response code was 200 
    r = response.read() 
    print r 
+0

Sollen Sie vorschlagen, dass die Anfragen nicht funktionieren? – doctorlove

+0

Das ist seltsam, diese Annahme zu machen ... –

+0

Vielen Dank für Ihre Antwort. Es funktioniert jedoch nicht. 'IOError: [Errno-Socket-Fehler] [Errno 111] Verbindung abgelehnt – njk

Verwandte Themen