Error while doing same curl api call using python

I have tried the curl request to update a internal user as following:

curl --insecure --cert ./elasticsearch-5.6.2/config/kirk.pem --key ./elasticsearch-5.6.2/config/kirk-key.pem -XPUT https://localhost:9200/_searchguard/api/user/kirk -d ’
{
“password”:“kirk1”,
“roles”:[“captains”, “starfleet”]
}’ --verbose

  • Trying 127.0.0.1…
  • Connected to localhost (127.0.0.1) port 9200 (#0)
  • found 173 certificates in /etc/ssl/certs/ca-certificates.crt
  • found 704 certificates in /etc/ssl/certs
  • ALPN, offering http/1.1
  • SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
  •  server certificate verification SKIPPED
    
  •  server certificate status verification SKIPPED
    
  •  common name: node-0.example.com (does not match 'localhost')
    
  •  server certificate expiration date OK
    
  •  server certificate activation date OK
    
  •  certificate public key: RSA
    
  •  certificate version: #3
    
  •  start date: Sun, 22 Apr 2018 03:43:47 GMT
    
  •  expire date: Wed, 19 Apr 2028 03:43:47 GMT
    
  •  issuer: DC=com,DC=example,O=Example Com Inc.,OU=Example Com Inc. Root CA,CN=Example Com Inc. Root CA
    
  •  compression: NULL
    
  • ALPN, server did not agree to a protocol

PUT /_searchguard/api/user/kirk HTTP/1.1
Host: localhost:9200
User-Agent: curl/7.47.0
Accept: /
Content-Length: 60
Content-Type: application/x-www-form-urlencoded

  • upload completely sent off: 60 out of 60 bytes
    < HTTP/1.1 200 OK
    < Warning: 299 Elasticsearch-5.6.2-57e20f3 “Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header.” “Wed, 11 Jul 2018 06:32:50 GMT”
    < content-type: application/json; charset=UTF-8
    < content-length: 45
    <
  • Connection #0 to host localhost left intact
    {“status”:“OK”,“message”:“User kirk updated”}

``

The call shows that Content-Type: application/x-www-form-urlencodedBut when similar call is made from python using requests.put I get error from server saying

u’{“error”:“Content-Type header [application/x-www-form-urlencoded] is not supported”,“status”:406}’

In [43]: d3
Out[43]:
{‘password’: ‘kirk123’,
‘roles’: [u’sg_own_index’, u’sg_public’, u’sg_role_starfleet’, u’sg_role_starfleet_captains’]}

In [44]: r3 = requests.put(“https://localhost:9200/_searchguard/api/user/kirk",data=d3,auth=HTTPBasicAuth(“kirk”,"kirk”),verify=False,cert=(’./elasticsearch-5.6.2/config/kirk.pem’,’./elasticsearch-5.6.2/config/kirk-key.pem’))

/env/lib/python2.7/site-packages/urllib3/connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)

In [45]: r3.text
Out[45]: u’{“error”:“Content-Type header [application/x-www-form-urlencoded] is not supported”,“status”:406}’

``

I am not able to understand when both reqeust use application/x-www-form-urlencoded why I am getting not supported error from server ?

When asking questions, please provide the following information:

  • Search Guard and Elasticsearch version
    5 / 5.6.2

  • Installed and used enterprise modules, if any

  • JVM version and operating system version

  • Search Guard configuration files

  • Elasticsearch log messages on debug levelEnter code here…

  • Other installed Elasticsearch or Kibana plugins, if any

···
  •  subject: DC=de,L=test,O=node,OU=node,CN=node-0.example.com
    

Found the Issue: The call needed use of json.dumps(d3)

`r3 = requests.put(“https://localhost:9200/_searchguard/api/user/kirk”,data=json.dumps(d3),auth … … …

`On Wednesday, July 11, 2018 at 12:23:25 PM UTC+5:30, Amey Gat wrote:

···

I have tried the curl request to update a internal user as following:

curl --insecure --cert ./elasticsearch-5.6.2/config/kirk.pem --key ./elasticsearch-5.6.2/config/kirk-key.pem -XPUT https://localhost:9200/_searchguard/api/user/kirk -d ’
{
“password”:“kirk1”,
“roles”:[“captains”, “starfleet”]
}’ --verbose

  • Trying 127.0.0.1…
  • Connected to localhost (127.0.0.1) port 9200 (#0)
  • found 173 certificates in /etc/ssl/certs/ca-certificates.crt
  • found 704 certificates in /etc/ssl/certs
  • ALPN, offering http/1.1
  • SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
  •  server certificate verification SKIPPED
    
  •  server certificate status verification SKIPPED
    
  •  common name: [node-0.example.com](http://node-0.example.com) (does not match 'localhost')
    
  •  server certificate expiration date OK
    
  •  server certificate activation date OK
    
  •  certificate public key: RSA
    
  •  certificate version: #3
    
  •  subject: DC=de,L=test,O=node,OU=node,CN=[node-0.example.com](http://node-0.example.com)
    
  •  start date: Sun, 22 Apr 2018 03:43:47 GMT
    
  •  expire date: Wed, 19 Apr 2028 03:43:47 GMT
    
  •  issuer: DC=com,DC=example,O=Example Com Inc.,OU=Example Com Inc. Root CA,CN=Example Com Inc. Root CA
    
  •  compression: NULL
    
  • ALPN, server did not agree to a protocol

PUT /_searchguard/api/user/kirk HTTP/1.1
Host: localhost:9200
User-Agent: curl/7.47.0
Accept: /
Content-Length: 60
Content-Type: application/x-www-form-urlencoded

  • upload completely sent off: 60 out of 60 bytes
    < HTTP/1.1 200 OK
    < Warning: 299 Elasticsearch-5.6.2-57e20f3 “Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header.” “Wed, 11 Jul 2018 06:32:50 GMT”
    < content-type: application/json; charset=UTF-8
    < content-length: 45
    <
  • Connection #0 to host localhost left intact
    {“status”:“OK”,“message”:“User kirk updated”}

``

In [43]: d3
Out[43]:
{‘password’: ‘kirk123’,
‘roles’: [u’sg_own_index’, u’sg_public’, u’sg_role_starfleet’, u’sg_role_starfleet_captains’]}

In [44]: r3 = requests.put(“https://localhost:9200/_searchguard/api/user/kirk”,data=d3,auth=HTTPBasicAuth(“kirk”,“kirk”),verify=False,cert=(’./elasticsearch-5.6.2/config/kirk.pem’,’./elasticsearch-5.6.2/config/kirk-key.pem’))

/env/lib/python2.7/site-packages/urllib3/connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)

In [45]: r3.text
Out[45]: u’{“error”:“Content-Type header [application/x-www-form-urlencoded] is not supported”,“status”:406}’

``

  • Search Guard and Elasticsearch version
    5 / 5.6.2
  • Installed and used enterprise modules, if any
  • JVM version and operating system version
  • Search Guard configuration files
  • Elasticsearch log messages on debug levelEnter code here…
  • Other installed Elasticsearch or Kibana plugins, if any

The call shows that Content-Type: application/x-www-form-urlencodedBut when similar call is made from python using requests.put I get error from server saying
u’{“error”:“Content-Type header [application/x-www-form-urlencoded] is not supported”,“status”:406}’
I am not able to understand when both reqeust use application/x-www-form-urlencoded why I am getting not supported error from server ?

When asking questions, please provide the following information: