Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 无法使用python和请求发布到solr服务器_Python 2.7_Solr_Python Requests_Solr4 - Fatal编程技术网

Python 2.7 无法使用python和请求发布到solr服务器

Python 2.7 无法使用python和请求发布到solr服务器,python-2.7,solr,python-requests,solr4,Python 2.7,Solr,Python Requests,Solr4,这是我试图实现的代码:- import requests import tornado.ioloop import tornado.web import tornado.autoreload import json class MainHandler(tornado.web.RequestHandler): def get(self): payload = [{"id" : "978-0641723445", "cat" : ["book","hardc

这是我试图实现的代码:-

import requests
import tornado.ioloop
import tornado.web
import tornado.autoreload
import json

class MainHandler(tornado.web.RequestHandler):
        def get(self):
            payload = [{"id" : "978-0641723445", "cat" : ["book","hardcover"], "name" : "The Lightning Thief", "author" : "Rick Riordan","series_t" : "Percy Jackson  Olympians", "sequence_i" : 1, "genre_s" : "fantasy", "inStock" : True, "price" : 12.50, "pages_i" : 384}]
            url = 'http://localhost:8983/solr/update/json'
            headers = {'content-type' : 'application/json'}
            # files = {'file': ('books.json', open('books.json', 'rb'))}
            timeline = requests.post(url, data = json.dumps(payload), headers = headers)
            self.write(timeline.text)
class QueryHandler(tornado.web.RequestHandler):
        def get(self):
            # timeline = requests.get('http://localhost:8983/solr/collection1/select?q=a&wt=json&indent=true')
            payload = {'q' : 'a', 'wt' : 'json', 'indent' : True}
            timeline = requests.get('http://localhost:8983/solr/collection1/select', params = payload)
            self.write(timeline.json())
application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/query", QueryHandler)
])

if __name__ == "__main__":
    application.listen(8888)
    io_loop = tornado.ioloop.IOLoop.instance()
    tornado.autoreload.start(io_loop)
    io_loop.start()
我能够在localhost:8888/query上查询solr服务器 但在我试图发布数据的localhost:8888上,我从solr得到以下响应:-

{
responseHeader: {
status: 0,
QTime: 46
}
}
数据未发布到solr服务器


任何建议???

代码标题中不包含
commitWithin
信息。该参数以毫秒为单位。只有在提交之后,数据才可从Solr进行搜索。下面可以作为向solr发布数据的示例。将JSON头连同
commitWithin
time和数据作为JSON字符串添加到
data
param中

requests.post(“http://localhost:8983/solr/collection1/update?wt=json,headers={“Content Type”:“application/json”},data={“add”:{“doc”:{“id”:14,“log_Type”:“debug”,“log_text”:“来自Kimy的调试事务”},“boost”:1.0,“overwrite”:true,“commitWithin”:1000}”)

答复:


{“responseHeader”:{“status”:0,“QTime”:128}

您解决过这个问题吗?面对类似的问题,我确实设法解决了。但是我似乎记不起来了,而且我也没有可以发布的代码。如果我能找到代码,我会加上答案