python - 在同一本地主机上的python本地主机请求具有不同的端口

标签 python elasticsearch 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)

请注意,我已经尝试通过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/

相关文章:

python - 图像中土壤颗粒分水岭以外的替代分割技术

python - sep = '|' 在 pandas 数据框中无法正常运行

python - 处理linux系统关机操作 "gracefully"

apache - 使用 Apache 的本地主机的自签名 SSL 证书

ruby-on-rails-3 - 子域约束(Rails 3)使本地服务器(瘦)如此慢

android - 开发过程中在android中调用REST API

python - 从 Python 字典中删除 None 值

java - 如何在搜索 API 中排除源字段?

elasticsearch - 如何在 ElasticSearch 中记录来自 Logstash 的已删除重复消息的数量?

java - 自动将 ElasticSearch 与 SQL 同步