I have a python script and when I try to connect to an elasticsearch cluster that is using shield and the user's password contains special characters I am unable to connect.
python script is unable to connect to es cluster due to problems parsing the special characters.
connection string is https://test:%23passw0rd%23@myhost:9200
I've tried using it with and without quote_plus from urllib but have been unable to connect.
without urllib.quote_plus I get the following error:
ValueError: invalid literal for int() with base 10: ''
with urlib.quote_plus I get a connection error:
/usr/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py:54: UserWarning: Connecting to myhost using SSL with verify_certs=False is insecure.
'Connecting to %s using SSL with verify_certs=False is insecure.' % host)
Traceback (most recent call last):
File "./es.py", line 65, in
indices = es.indices.get(index='*')
File "/usr/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/lib/python2.7/site-packages/elasticsearch/client/indices.py", line 130, in get
File "/usr/lib/python2.7/site-packages/elasticsearch/transport.py", line 307, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/usr/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 89, in perform_request
raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.VerifiedHTTPSConnection object at 0x1e37fd0>: Failed to establish a new connection: [Errno -2] Name or service not known) caused by: NewConnectionError(<urllib3.connection.VerifiedHTTPSConnection object at 0x1e37fd0>: Failed to establish a new connection: [Errno -2] Name or service not known)
script is below:
username = 'test'
password = urllib.quote_plus('#passw0rd#')
hostname = 'myhost'
port = '9200'
if '--ssl' in args:
proto = 'https://'
proto = 'http://'
url = proto + username + ':' + password + '@' + hostname + ':' + port
es = elasticsearch([url])
except Exception, err:
print 'error: connection failed'