Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.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 无法将JSON发布到ElasticSearch-找不到uri[\]和方法[post]的处理程序_Python_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Post_Httphandler_Http Status Code 400 - Fatal编程技术网 elasticsearch,post,httphandler,http-status-code-400,Python,elasticsearch,Post,Httphandler,Http Status Code 400" /> elasticsearch,post,httphandler,http-status-code-400,Python,elasticsearch,Post,Httphandler,Http Status Code 400" />

Python 无法将JSON发布到ElasticSearch-找不到uri[\]和方法[post]的处理程序

Python 无法将JSON发布到ElasticSearch-找不到uri[\]和方法[post]的处理程序,python,elasticsearch,post,httphandler,http-status-code-400,Python,elasticsearch,Post,Httphandler,Http Status Code 400,我尝试将一些数据,JSON格式,从mongoDB发布到elasticSearch 这是我的密码: 首先,我从mongoDB中提取数据,然后尝试将每个“文档”发布到我的elastic,地址是“”。我添加了一个额外的函数“my converter(o)”,以使datetime对象可序列化 from pymongo import MongoClient import requests import json import datetime mongo_host = 'localhost' mongo

我尝试将一些数据,JSON格式,从mongoDB发布到elasticSearch

这是我的密码:

首先,我从mongoDB中提取数据,然后尝试将每个“文档”发布到我的elastic,地址是“”。我添加了一个额外的函数“my converter(o)”,以使datetime对象可序列化

from pymongo import MongoClient
import requests
import json
import datetime

mongo_host = 'localhost'
mongo_port = '27017'

client=MongoClient(mongo_host+':'+mongo_port)
db = client.cvedb
collection=db['cves']

def myconverter(o):
     if isinstance(o, datetime.datetime):
            return o.__str__()



try: db.command("serverStatus")
except Exception as e: print(e)
else: print("You are connected!")
cursor = collection.find({})
for document in cursor:

    headers={"content-type":"application/x-www-form-urlencoded"}

    url_base = 'http://127.0.0.1:9200'

    data=document

    data_parsed=(json.dumps(data, default = myconverter))

    print("#####")
    print("#####")
    print(data_parsed)
    print("#####")
    print("#####")

    req = requests.post(url_base,json=data_parsed)
    print (req.status_code)
    print (req.text)

    print("####")
    print("#####")
    print (req.status_code)
    print("#####")
    print("####")
client.close()
但是当我在下面的地址上点击我的ES时,什么也没有出现。以下是我通过终端获得的信息:

{"Modified": "2008-09-09 08:35:18.883000", "impact": {"confidentiality": "PARTIAL", "integrity": "PARTIAL", "availability": "PARTIAL"}, "summary": "KDE K-Mail allows local users to gain privileges via a symlink attack in temporary user directories.", "cvss": 4.6, "access": {"vector": "LOCAL", "authentication": "NONE", "complexity": "LOW"}, "vulnerable_configuration": ["cpe:2.3:a:kde:k-mail:1.1"], "_id": null, "references": ["http://www.redhat.com/support/errata/RHSA1999015_01.html", "http://www.securityfocus.com/bid/300"], "Published": "2000-01-04 00:00:00", "id": "CVE-1999-0735", "cvss-time": "2004-01-01 00:00:00", "vulnerable_configuration_cpe_2_2": ["cpe:/a:kde:k-mail:1.1"]}
#####
#####
400
No handler found for uri [/] and method [POST]
####
#####
400
#####
####
#####
#####
我试着跟随同一个问题的《我的邮报》,但没有任何效果。 知道它为什么不起作用吗?

有两个问题

  • url\u base
    缺少索引和类型

    url_base=“”

  • headers
    必须是
    application/json
    (您还没有看到这一点,但是一旦您解决了上面的问题,您也会遇到这个错误

    标题={“内容类型”:“应用程序/json”}