python - BTC.COM API:HTTP 错误 414:请求 URI 太大
问题描述
我正在尝试连接到 BTC.COM API 并查询一系列钱包(大约 500,000 个钱包)的余额。一次调用中的 API 似乎太多了。您能帮助阅读错误并进行调试吗?我的理解是查询太大,但我不知道在哪里看才能知道限制。一次调用 API 处理多少个钱包?任何贡献表示赞赏。
API 代码为:
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
错误:
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>
解决方案
API
我将在一般情况下回答这个问题,因为我在参考文献中找不到所需的详细信息。
414
错误代码通常可以通过使用请求来解决POST
:将查询字符串转换为 json 对象并使用 POST 发送到 API 请求
对于GET
请求,请求的最大长度取决于服务器端和客户端。大多数网络服务器都有 8k 的限制,这是可配置的。在客户端,不同的浏览器有不同的限制。浏览器 IE 和 Safari 限制为 2k、Opera 4k 和 Firefox 8k。表示 GET 请求的最大长度为 8k,最小请求长度为 2k。
您也可以考虑这样的解决方法
假设您的 URI 有一个太长的字符串 stringdata。您可以根据服务器的限制将其简单地分解为多个部分。然后提交第一个,在我的情况下写一个文件。然后提交下一个以附加到先前添加的数据。 资源
推荐阅读
- php - 如何在我的网站上弃用对 Internet Explorer 的支持
- c# - context.EnsureCreated() 抛出异常 - 已经是一个名为
- arduino - 如何通过串行向arduino发送数字?
- python - LIME 特征值不匹配
- mocking - Mock 在构建时无法安装 RPM 依赖项,但可以“安装”它
- java - Jackson 与 ParameterNamesModule 未能反序列化类
- android - 无论布局类型如何,如何在屏幕中心显示 ProgressBar
- android - 如何从 Kotlin DSL build.gradle 中的所有依赖项中排除库?
- odoo - 如何修复网站销售模块中 [/shop/checkout] 和 [/payment] 之间的 ODOO 9 送货地址不匹配?
- python - 安装 Jupyter Hub 后,Conda 不再工作