2017-06-15 101 views
1

我試圖用捲曲的蟒蛇到彈性搜索推此命令使指數模式得到的代碼之後創建完成Python的捲曲彈性搜索問題

 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() 

輸出返回是: -

* 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} 

什麼可能是問題並解決這個問題?

回答

2

你在apiURL中有額外的'-d'。我想這是從命令行復制&粘貼。如果沒有,那麼你必須編碼url(urllib.urlencode)