question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed in async module

See original GitHub issue

Just to leave a reminder about this bug. I know you are aware of it but the other bug that was closed was for the sync module of ccxt.

  • OS: OSX
  • Language: Python
  • CCXT version: 1.10.443
  • Exchange:kraken, bitfinex
  • Method: fetch_balance() (async version)
import asyncio
import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')

import ccxt.async as ccxt  # noqa: E402


async def test(exchange):
    print(await exchange.fetch_balance())


kraken = ccxt.kraken({
    'apiKey': "hEvQNMDIeoCJbr7W/ZBb5CGOrx3G0lWF5B3zqa1JBxdZlEaL8EK+D0Mw",
    'secret': "JaE9wI6Nwgh5oRxiHcVxurwzwBxwc05W/qv/k1srGg4s3EYuXPpNkLLM5NYbbWpM8rCyijIeDavRuqWbU0ZV9A==",
    'verbose': True,  # switch it to False if you don't want the HTTP log
})
bitfinex = ccxt.bitfinex({
    'apiKey': "4FlEDtxDl35gdEiobnfZ72vJeZteE4Bb7JdvqzjIjHq",
    'secret': "D4DXM8DZdHuAq9YptUsb42aWT1XBnGlIJgLi8a7tzFH",
    'verbose': True,  # switch it to False if you don't want the HTTP log
})

[asyncio.ensure_future(test(exchange)) for exchange in [kraken, bitfinex]]
pending = asyncio.Task.all_tasks()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*pending))
/Users/hexdump/Developing/Python/arbitragebot/venv/bin/python /Users/hexdump/Developing/Python/arbitragebot/asyncmain.py
https://api.kraken.com/0/public/AssetPairs GET https://api.kraken.com/0/public/AssetPairs 
Request: {'Accept-Encoding': 'gzip, deflate'} None
https://api.bitfinex.com/v1/symbols_details GET https://api.bitfinex.com/v1/symbols_details 
Request: {'Accept-Encoding': 'gzip, deflate'} None
Traceback (most recent call last):
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 796, in _wrap_create_connection
    return (yield from self._loop.create_connection(*args, **kwargs))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 803, in create_connection
    sock, protocol_factory, ssl, server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 829, in _create_connection_transport
    yield from waiter
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 503, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 201, in feed_ssldata
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/ccxt/async/base/exchange.py", line 104, in fetch
    async with session_method(url, data=encoded_body, headers=headers, timeout=(self.timeout / 1000), proxy=self.aiohttp_proxy) as response:
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/aiohttp/client.py", line 690, in __aenter__
    self._resp = yield from self._coro
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/aiohttp/client.py", line 267, in _request
    conn = yield from self._connector.connect(req)
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 402, in connect
    proto = yield from self._create_connection(req)
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 748, in _create_connection
    _, proto = yield from self._create_direct_connection(req)
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 859, in _create_direct_connection
    raise last_exc
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 831, in _create_direct_connection
    req=req, client_error=client_error)
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 801, in _wrap_create_connection
    raise ClientConnectorSSLError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorSSLError: Cannot connect to host api.bitfinex.com:443 ssl:True [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/hexdump/Developing/Python/arbitragebot/asyncmain.py", line 29, in <module>
    loop.run_until_complete(asyncio.gather(*pending))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/Users/hexdump/Developing/Python/arbitragebot/asyncmain.py", line 12, in test
    print(await exchange.fetch_balance())
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/ccxt/async/bitfinex.py", line 280, in fetch_balance
    await self.load_markets()
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/ccxt/async/base/exchange.py", line 126, in load_markets
    markets = await self.fetch_markets()
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/ccxt/async/bitfinex.py", line 238, in fetch_markets
    markets = await self.publicGetSymbolsDetails()
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/ccxt/async/bitfinex.py", line 646, in request
    response = await self.fetch2(path, api, method, params, headers, body)
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/ccxt/async/base/exchange.py", line 84, in fetch2
    return await self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/ccxt/async/base/exchange.py", line 115, in fetch
    self.raise_error(ExchangeError, url, method, e, None)
  File "/Users/hexdump/Developing/Python/arbitragebot/venv/lib/python3.6/site-packages/ccxt/base/exchange.py", line 271, in raise_error
    details,
ccxt.base.errors.ExchangeError: bitfinex GET https://api.bitfinex.com/v1/symbols_details Cannot connect to host api.bitfinex.com:443 ssl:True [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)] 

Process finished with exit code 1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
kroitorcommented, Jan 1, 2018

Not very easy to find an adequate implementation of python-requests in an async environment… But as a temporary workaround you can do the following:

  1. Install certifi with pip3 install certifi

  2. Get the path of the new cert.pem CA file from certifi:

    python -c "import certifi; print(certifi.where())"
    
  3. Get default system path for old CA files:

    python -c "import ssl; print(ssl.get_default_verify_paths())"
    
  4. Copy (or replace) the CA file from path 2 to path 3.

1reaction
jochem-brouwercommented, Dec 30, 2017

Hey, I had a similiar issue, and fixed it by updating requests.

pip install --upgrade requests

Read more comments on GitHub >

github_iconTop Results From Across the Web

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed ...
python - ssl. SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl. c:997) - ...
Read more >
"certificate verify failed" SSL error when trying to ... - Reddit
It means that your client could not verify the server's certificate in order to properly start an HTTPS connection. It also means that...
Read more >
[ssl: certificate_verify_failed] certificate verify failed: unable to ...
I'm developing with python 3.9.6. I encounter this error... ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to ...
Read more >
HTTPS | Node.js v19.3.0 Documentation
... protocol over TLS/SSL. In Node.js this is implemented as a separate module. ... When using CommonJS, the error thrown can be caught...
Read more >
Transports — Zeep 4.1.0 documentation
Make sure that the certificate you refer to is a CA_BUNDLE, meaning it contains a root CA and an intermediate CA. Accepted are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found