[英]Why does BLOCKCHAIN.COM API only return recipient BASE58 addresses and omits BECH32s?
[英]How to get response from blockchain.com by using wss in Python?
我尝试使用此 API 连接到 blockchain.com websocket 。 我为 Python 使用 websockets 库。 当我使用交互式客户端方法连接时,我成功了。 但是当我尝试使用我的 Python 脚本进行连接时,我没有来自服务器套接字的任何响应。 这是我的脚本:
import asyncio
import websockets
async def main():
async with websockets.connect("wss://ws.blockchain.info/inv") as client:
print(await client.recv())
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
这是我在使用交互式客户端时在终端中所拥有的,我希望在运行脚本时看到它:
Connected to wss://ws.blockchain.info/inv.
>
正如@SteffenUllrich 在评论中提到的那样,此文本由interactive client
显示-它不是从服务器接收到的消息-您必须使用自己的print("Connected to wss://ws.blockchain.info/inv.")
来显示它.
如果您想从服务器recv()
某些东西,那么首先您必须向服务器send()
命令。
import asyncio
import websockets
async def main():
async with websockets.connect("wss://ws.blockchain.info/inv") as client:
print("[main] Connected to wss://ws.blockchain.info/inv" )
cmd = '{"op":"ping"}'
print('[main] Send:', cmd)
await client.send(cmd)
print('[main] Recv:', await client.recv())
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
结果:
[main] Connected to wss://ws.blockchain.info/inv
[main] Send: {"op":"ping"}
[main] Recv: {"op":"pong"}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.