我在localhost(http://localhost:5000
)中使用Flash并尝试使用python请求从elasticsearch请求json结果
这是我的代码
@app.route('/test')
def TestElasticsearch():
url = "http://localhost:9200/customer/_search?q=James&size=5"
r = requests.get(url)
print r
return r.text
当我通过谷歌浏览器访问http://localhost:5000/test
时,它会返回
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)
请注意,我尝试通过谷歌浏览器访问http://localhost:9200/customer/_search?q=James&size=5
,但它确实有效。
请帮我解决问题
答案 0 :(得分: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