1

Iam trying to make an API call to a HTTPS url:

response = requests.request("GET", url, headers=headers, params=None, verify=True)

and Iam facing the following error. It works fine when i invoke the API via cUrl or Postman...

Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen chunked=chunked) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request self._validate_conn(conn) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn conn.connect() File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connection.py", line 326, in connect ssl_context=context) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 448, in wrap_socket raise ssl.SSLError('bad handshake: %r' % e) ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\adapters.py", line 440, in send timeout=timeout File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen _stacktrace=sys.exc_info()[2]) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\util\retry.py", line 388, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='freshdesk.freshsales.io', port=443): Max retries exceeded with url: /api/sales_accounts/1000080286/conversations.json?include=email_conversation_recipients,all,targetable,phone_numbe,phone_calle,note,user (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

I tried by specifying verify=False .Still there is error

C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connectionpool.py:858: 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) Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 441, in wrap_socket cnx.do_handshake() File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\OpenSSL\SSL.py", line 1716, in do_handshake self._raise_ssl_error(self._ssl, result) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\OpenSSL\SSL.py", line 1456, in _raise_ssl_error _raise_current_error() File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\OpenSSL_util.py", line 54, in exception_from_error_queue raise exception_type(errors) OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen chunked=chunked) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request self._validate_conn(conn) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn conn.connect() File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\connection.py", line 326, in connect ssl_context=context) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 448, in wrap_socket raise ssl.SSLError('bad handshake: %r' % e) ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

Any ideas on how i can circumvent this error ? I Browsed through various questions here but could not find a solution for this. The URL administrator also confirmed that the server certificates are valid so i feel this has definitely got to do something with some conflicting package installation.

Here's my pip freeze list of packages:

C:\Users\user\python>pip freeze
asn1crypto==0.23.0
attrs==16.3.0
Automat==0.5.0
beautifulsoup4==4.5.3
bleach==1.5.0
bs4==0.0.1
certifi==2017.7.27.1
cffi==1.11.2
chardet==3.0.4
chargebee==2.1.8
colorama==0.3.7
constantly==15.1.0
cryptography==2.1.1
cssselect==1.0.1
decorator==4.0.11
entrypoints==0.2.2
html5lib==0.9999999
idna==2.6
incremental==16.10.1
ipykernel==4.5.2
ipython==5.3.0
ipython-genutils==0.1.0
ipywidgets==5.2.2
Jinja2==2.9.5
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.0.0
jupyter-console==5.1.0
jupyter-core==4.3.0
lxml==3.7.3
MarkupSafe==0.23
mistune==0.7.3
nbconvert==5.1.1
nbformat==4.3.0
notebook==4.4.1
numpy==1.12.0
pandas==0.19.2
pandocfilters==1.4.1
parsel==1.1.0
pickleshare==0.7.4
prompt-toolkit==1.0.13
pyasn1==0.2.3
pyasn1-modules==0.0.8
pycparser==2.18
PyDispatcher==2.0.5
Pygments==2.2.0
PyJWT==1.5.0
pyOpenSSL==17.3.0
PySocks==1.6.7
python-dateutil==2.6.0
pytz==2016.10
pyzmq==16.0.2
qtconsole==4.2.1
queuelib==1.4.2
requests==2.18.4
selenium==3.0.2
service-identity==16.0.0
simplegeneric==0.8.1
six==1.11.0
testpath==0.3
tornado==4.4.2
traitlets==4.3.2
twilio==6.0.0
urllib3==1.22
w3lib==1.17.0
wcwidth==0.1.7
widgetsnbextension==1.2.6
win-unicode-console==0.5
zope.interface==4.3.3

1 Answer 1

4

Finally figured out that it was a Network issue. Took this up with my company's IT team and they resolved it by doing some IP whitelisting.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.