2017-06-15 6 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() 

戻されて出力され終了した後にインデックスパターンが作成されますように弾性検索でこのコマンドをプッシュするpythonでカールを使用しようとしています: -

* 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)をエンコードする必要があります