Solana JSON RPC 请求超时
Posted
技术标签:
【中文标题】Solana JSON RPC 请求超时【英文标题】:Solana JSON RPC requests time out 【发布时间】:2021-10-14 21:35:42 【问题描述】:我正在尝试使用文档 (https://docs.solana.com/developing/clients/jsonrpc-api) 中的 API 示例从 Solana 区块链中查询信息。我正在使用:
curl https://api.mainnet-beta.solana.com:8899 -X POST -H "Content-Type: application/json" -d '
"jsonrpc": "2.0",
"id": 1,
"method": "getBalance",
"params": [
"KEY"
]
'
每当我运行它时,我都会收到超时错误:
curl: (7) Failed to connect to api.mainnet-beta.solana.com port 8899: Timed out
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Couldn't resolve host 'jsonrpc'
curl: (6) Couldn't resolve host '2.0,'
curl: (6) Couldn't resolve host 'id'
curl: (6) Couldn't resolve host '1,'
curl: (6) Couldn't resolve host 'method'
curl: (6) Couldn't resolve host 'getBalance,'
curl: (6) Couldn't resolve host 'params'
curl: (3) [globbing] bad range specification in column 2
curl: (6) Couldn't resolve host 'Key'
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
我在这里做错了吗?有人可以解释为什么这不起作用吗?我也尝试过使用 Python:
import requests
import json
url = "https://api.mainnet-beta.solana.com:8899"
payload =
"jsonrpc": "2.0",
"id": 1,
"method": "getBalance",
"params": [
"KEY"
]
response = requests.post(url, json=payload).json()
print(response)
KEY
是钱包地址
还有另一个超时错误:https://pastebin.com/38BC2xds。 有人能解释一下为什么这不起作用以及我需要做些什么来解决它吗?
【问题讨论】:
【参考方案1】:访问主集群时不需要端口号,可以试试:
$ curl https://api.mainnet-beta.solana.com -X POST -H "Content-Type: application/json" -d '"jsonrpc":"2.0", "id":1, "method":"getBalance", "params":["83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"]'
应该给出如下内容:
"jsonrpc":"2.0","result":"context":"slot":101535695,"value":0,"id":1
除了槽号在你运行的时候会更高。
【讨论】:
以上是关于Solana JSON RPC 请求超时的主要内容,如果未能解决你的问题,请参考以下文章
Cassandra 具有长 IN 运算符的慢速(rpc 超时)读取请求