-1

I am trying to connect to BTC.COM API and query for balances on a universe of wallets (approx. 500,000 wallets). It looks like it is too much for the API within one call. Could you help to read the error and to debug? My understanding is that the query is too big but I don't know where to look to know the limit. How many wallet the API handle for one call? Any contribution is appreciated.

The API code is:

class MultiAddress:
    def __init__(self, a):
        self.final_balance = a['wallet']['final_balance']
    def __repr__(self):
            return "{"f'"balance": {self.final_balance}'"}"

def get_multi_address(addresses):
    response = util.call_api(resource)
    json_response = json.loads(response)
    return MultiAddress(json_response)

p = get_multi_address(addresses=tuple_of_addresses)
sum_bal = p.final_balance

The error:

Traceback (most recent call last):
  File "/Users/lolo/Documents/MARKET_RISK/python/util.py", line 32, in call_api
    response = urlopen(base_url + resource, payload, timeout=TIMEOUT).read()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 414: Request-URI Too Large

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "explo_bal.py", line 56, in <module>
    p = get_multi_address(addresses=tuple_of_addresses)
  File "/Users/delalma/Documents/MARKET_RISK/python/explorer.py", line 165, in get_multi_address
    response = util.call_api(resource)
  File "/Users/delalma/Documents/MARKET_RISK/python/util.py", line 36, in call_api
    raise APIException(handle_response(e.read()), e.code)
util.APIException: <html>
<head><title>414 Request-URI Too Large</title></head>
<body>
<center><h1>414 Request-URI Too Large</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
delalma
  • 838
  • 3
  • 12
  • 24

1 Answers1

0

I will answer this in a general context as I can't find the required details on the API in reference.

The 414 error-code can normally be solved By using a POST request: Convert query string to json object and sent to API request with POST

With GET requests, Max length of the request depends on server side as well as client-side. Most webserver has limit 8k which is configurable. On the client-side, the different browser has a different limit. The browser IE and Safari limit to 2k, Opera 4k, and Firefox 8k. means the max length for the GET request is 8k and min request length is 2k.

You can also consider a workaround like so

Suppose your URI has a string stringdata that is too long. You can simply break it into a number of parts depending on the limits of your server. Then submit the first one, in my case to write a file. Then submit the next ones to append to previously added data. source

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35