我在本地主机(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)
请注意,我已经尝试通过Google chrome访问
http://localhost:9200/customer/_search?q=James&size=5
,并且它可以正常工作。请帮我找出问题所在
最佳答案
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
关于python - 在同一本地主机上的python本地主机请求具有不同的端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42156149/