The following function execution throws an error. The same command in bash works like a charm.
def set_kibana_password():
headers = {"Content-Type": "application/json"}
payload = {"password": os.getenv('ELASTIC_PASSWORD')}
response = requests.put(
url='https://localhost:9200/_xpack/security/user/kibana/_password',
auth=HTTPBasicAuth('elastic', os.getenv('ELASTIC_PASSWORD')),
cert='/certs/ca/ca.crt',
headers=headers,
data=payload
)
logging.info(str(response))
The output:
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:9200
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
conn.connect()
File "/usr/lib/python3.7/site-packages/urllib3/connection.py", line 344, in connect
ssl_context=context)
File "/usr/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 335, in ssl_wrap_socket
context.load_cert_chain(certfile, keyfile)
ssl.SSLError: [SSL] PEM lib (_ssl.c:3845)
Bash:
curl -u elastic:$ELASTIC_PASSWORD -X PUT -H 'Content-Type: application/json' \
--cacert /certs/ca/ca.crt \
'https://localhost:9200/_xpack/security/user/kibana/_password' \
-d '{ "password": "$ELASTIC_PASSWORD" }'