2017-02-10 6 views
2

私はローカルホストのフラッシュ(http://localhost:5000)を使用してelasticsearchPythonのlocalhostの別のポートと同じローカルホスト上の要求

からJSON結果を要求するためのpythonの要求を使用しようとしている。ここに私のコードは、とき

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

です私はGoogleのクロムを経由してhttp://localhost:5000/testにアクセスし、それは私がGoogleのCを介してhttp://localhost:9200/customer/_search?q=James&size=5にアクセスしようとした

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) 

注意を返します。 hromeとそれは動作します。

私は問題

+0

を見つけ出す助けてくださいlocalhostの代わりに127.0.0.1を使用してみてください。 –

答えて

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

リクエストのlibがうまくいかないことをお勧めしますか? – doctorlove

+0

この仮定をするのは変です... –

+0

あなたの答えをありがとう。ただし、動作しません。 'IOError:[Errnoソケットエラー] [Errno 111] Connection refused' – njk

関連する問題