APIError(code=0): Invalid JSON error message from Binance:

Hello everyone,

I made a program to automate my trading strategy with Binance API in Python.
It worked fine for about 2 weeks. But now I sometimes have an error like this one :

APIError(code=0): Invalid JSON error message from Binance: <!DOCTYPE html>
<!-- saved from url=(0032)https://www.binance.com/en/error -->
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

  <meta name="format-detection" content="telephone=no,email=no,address=no">
  <title>Binance</title>
  <link rel="Shortcut Icon" href="https://www.binance.com/en/favicon.ico">
  <style>
    body {
      margin: 0
    }

    .img {
      width: 611px;
      margin: 68px auto 0
    }

    .info {
      width: 370px;
      margin: 0 auto;
      text-align: center;
      font-family: Arial;
    }

    .info h3 {
      margin: 0;
      font-size: 25px;
      color: #333;
      font-weight: normal;
    }

    .info p {
      font-size: 14px;
      font-family: Arial;
      color: #333;
      line-height: 18px;
      margin: 0
    }

    .info button {
      margin-top: 20px;
      width: 231px;
      height: 34px;
      background: #FFFFFF;
      border: 1px solid #F0B90B;
      box-sizing: border-box;
      border-radius: 3px;
      font-size: 14px;
      line-height: 16px;
      color: #F0B90B;
    }
  </style>
</head>

<body>
  <div class="img"><img alt="" src="/errorPages/404.jpg"></div>
  <div class="info">
    <h3>出错啦!您访问的网页不存在。</h3>
    <p>Sorry! The page you’re looking for cannot be found.</p>
    <a href="https://www.binance.com">
      <button>Return to Binance home page</button>
    </a>
  </div>

</body>

</html>

I already tried to search something similar on the web but no success.

This error occurs randomly when the method Client.futures_account_balance() is called.
Most of the time it works but sometimes I get this.

Does someone know what it could be?
Thank you for your help

Hi there,

It would be helpful if you provided the snippet of code which is causing this error so we can take a closer look at identifying what the issue is. Thanks,

if openPos < max_trades :												
	
	try :
		bal = pd.DataFrame(client.futures_account_balance())			
	except Exception as e:
		print(f'\nErreur survenue à UTC :{end_time}\n{e}')
		exit()
	
	solde = float(bal[bal.asset == 'USDT'].withdrawAvailable.values[0])	

Here is the condition the program goes in if no position is already open on my account.
The error comes from the instruction in the try except block.

My program is started every minute from yesterday 09:30 UTC until the moment I am writing this message and the error occured at :
10:02 UTC yesterday
04:41, 07:06, 08:43 UTC today

2 Likes

I get a new error during the day

APIError(code=-5000): GET /fapi/v1/balance is retired, please use GET /fapi/v2/balance

So here is the point why it is not working but now I don’t really understand what I need to do. Because I do not use the endpoints directly.
I only call my functions from python-binance library and I checked, everything is up to date.
My program is running on a Raspberry Pi if it can make a difference …

please check which endpoint is called by the library, if it’s still using the v1, please update it to v2 as required.

Nothing to do with endpoint version, I am getting below error message when i call client.get_server_time(). could someone check and respond pls?

Error checking balance: APIError(code=0): Invalid JSON error message from Binance:

502 Bad Gateway

502 Bad Gateway


nginx