# Unable to connect to elasticsearch using elasticsearch-py when password contains special characters

**URL:** <https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-using-elasticsearch-py-when-password-contains-special-characters/35612>\
**Category:** Elasticsearch\
**Created:** [November 25, 2015, 10:55pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-using-elasticsearch-py-when-password-contains-special-characters/35612 "2015-11-25T22:55:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![etfeet](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@etfeet](https://discuss.elastic.co/u/etfeet)\
**Post date:** [November 25, 2015, 10:55pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-using-elasticsearch-py-when-password-contains-special-characters/35612/1 "2015-11-25T22:55:15Z")

</div>

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](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  
feature), params=params)  
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://'  
else:  
proto = 'http://'

url = proto + username + ':' + password + '@' + hostname + ':' + port  
es = elasticsearch([url])

try:  
es.ping()  
except Exception, err:  
print 'error: connection failed'  
sys.exit(1)

....

---

<div class="post-metadata">

**Author:** ![etfeet](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@etfeet](https://discuss.elastic.co/u/etfeet)\
**Post date:** [November 25, 2015, 11:54pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-using-elasticsearch-py-when-password-contains-special-characters/35612/2 "2015-11-25T23:54:14Z")

</div>

I fixed it. the server I was running the script from didn't have the ca cert installed =(

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:35pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-using-elasticsearch-py-when-password-contains-special-characters/35612/3 "2017-07-05T23:35:46Z")

</div>


