ccxt: Binance SSL: CERTIFICATE_VERIFY_FAILED

I’m trying to connect to binance, and just testing the load_markets function, but I’m getting an SSL error.

bin = ccxt.binance({'apiKey':BinanceKey1,'secret':BinanceSecret1})
bin.verbose = True
bin.load_markets()

And Output:

https://api.binance.com/api/v1/exchangeInfo GET https://api.binance.com/api/v1/exchangeInfo 
Request: {'User-Agent': 'ccxt/1.10.343 (+https://github.com/ccxt/ccxt) Python/3.6.3', 'Accept-Encoding': 'gzip, deflate'} None
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1026, in _send_output
    self.send(msg)
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 964, in send
    self.connect()
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 814, in __init__
    self.do_handshake()
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 319, in fetch
    response = opener.open(request, timeout=int(self.timeout / 1000))
  File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 526, in open
    response = self._open(req, data)
  File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 544, in _open
    '_open', req)
  File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/scoss/PycharmProjects/Bitcoin/ccxt_test.py", line 31, in <module>
    bin.load_markets()
  File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 786, in load_markets
    markets = self.fetch_markets()
  File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\binance.py", line 237, in fetch_markets
    response = self.publicGetExchangeInfo()
  File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\binance.py", line 669, in request
    response = self.fetch2(path, api, method, params, headers, body)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 277, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 338, in fetch
    self.raise_error(ExchangeNotAvailable, url, method, e)
  File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 259, in raise_error
    details,
ccxt.base.errors.ExchangeNotAvailable: binance GET https://api.binance.com/api/v1/exchangeInfo <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)> 

Not having issues with other exchanges, and this key/secret pair works without ccxt

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 39 (20 by maintainers)

Most upvoted comments

This issue is fixed in version 1.10.436. Can you guys test and verify it, please? We will be thankful for your reports!

@hexdump2002 today or tomorrow.

@hexdump2002

Will this affect the cctx.async part of the library?

No, if you mean breaking the async version, it will not affect the ccxt.async. But yes, if you mean switching the async to an async-compatible implementation of requests - it will affect the implementation only. The interface remains the same.

I mean, requests is not compatible with async

Yes, but we are not going to use the synchronous version of requests in our async subpackage, of course. We are going to integrate an async-aware implementation of requests, like requests-futures, or some other implementation that fits best for this job.

so we will have sync calls whenever we use async or not.

Nope, you will still have both sync and true-async modes available.

Hope it answers your question, let me know if you have more )

@kroitor also just wanted to echo the thanks for sharing the lib! The work that’s been done so far has been great!

@kroitor tested fix and working as expected now! Thanks again!

@aekramer

Will you let us know here when the async version is fixed?

Sure, it is coming next.

it seems to work with GDAX, but not when I change it to binance

Will look into it, thx for reporting.

Europe/Spain , I will provide anything you need 😃

I have executed what you suggested and this is the output:

{“timezone”:“UTC”,“serverTime”:1513694282583,“rateLimits”:[{“rateLimitType”:“REQUESTS”,“interval”:“MINUTE”,“limit”:1200},{“rateLimitType”:“ORDERS”,“interval”:“SECOND”,“limit”:10},{“rateLimitType”:“ORDERS”,“interval”:“DAY”,“limit”:100000}],“exchangeFilters”:[],“symbols”:[{“symbol”:“ETHBTC”,“status”:“TRADING”,“baseAsset”:“ETH”,“baseAssetPrecision”:8,“quoteAsset”:“BTC”,“quotePrecision”:8,“orderTypes”:

{“filterType”:“MIN_NOTIONAL”,“minNotional”:“0.01000000”}]},{“symbol”:“OSTBNB”,“status”:“TRADING”,“baseAsset”:“OST”,“baseAssetPrecision”:8,“quoteAsset”:“BNB”,“quotePrecision”:8,“orderTypes”:[“LIMIT”,“LIMIT_MAKER”,“MARKET”,“STOP_LOSS_LIMIT”,“TAKE_PROFIT_LIMIT”],“icebergAllowed”:true,“filters”:[{“filterType”:“PRICE_FILTER”,“minPrice”:“0.00001000”,“maxPrice”:“10000.00000000”,“tickSize”:“0.00001000”},{“filterType”:“LOT_SIZE”,“minQty”:“0.01000000”,“maxQty”:“10000000.00000000”,“stepSize”:“0.01000000”},{“filterType”:“MIN_NOTIONAL”,“minNotional”:“1.00000000”}]}]}

It seems to work correctly. I’m the one that reported #904

Thanks I’ll try the things you mentioned and report back…may take me a little while to do a clean anaconda install though