简体   繁体   English

Python卷曲到弹性搜索问题

[英]Python Curl To Elastic Search Issue

I am trying to use curl in python to push this command in Elastic search so that index patterns get created after the code finishes 我正在尝试在python中使用curl在弹性搜索中推送此命令,以便在代码完成后创建索引模式

        import pycurl
        import urllib
        import urllib2
        apiURL = 'http://localhost:9200/.kibana/index-pattern/james+_alerts* -d'
        c = pycurl.Curl()
        c.setopt(c.URL, apiURL)
        c.setopt(c.POSTFIELDS, '{"title" : james+"_alerts*",  "timeFieldName": "timeStamp"}')
        c.setopt(c.VERBOSE, True)
        c.perform()     
        c.close()

The output being returned is: - 返回的输出为:-

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9200 (#0)
> POST /.kibana/index-pattern/james+_alerts* -d HTTP/1.1
Host: localhost:9200
User-Agent: PycURL/7.43.0 libcurl/7.52.1 GnuTLS/3.5.6 zlib/1.2.11 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) librtmp/2.3
Accept: */*
Content-Length: 56
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 56 out of 56 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 400 Bad Request
< content-type: application/json; charset=UTF-8
< content-length: 207
< 
* Curl_http_done: called premature == 0
* Closing connection 0
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"invalid version format: -D HTTP/1.1"}],"type":"illegal_argument_exception","reason":"invalid version format: -D HTTP/1.1"},"status":400}

What could potentially be the issue and fix for this? 有什么潜在的问题和解决办法?

You have extra '-d' in apiURL. 您在apiURL中有额外的“ -d”。 I guess that it came from copy&paste from command line. 我猜它来自命令行的复制和粘贴。 If not, then you must encode url (urllib.urlencode) 如果不是,那么您必须对URL进行编码(urllib.urlencode)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM