python sdk hyperledger连接通过“无法连接到所有地址”

2024-06-30 16:15:22 发布

您现在位置:Python中文网/ 问答频道 /正文

从docker容器连接到hyperledger网络时遇到问题。 我在虚拟机上安装了Hyperledger fabric 1.4,其中有一个docker容器和fabric python sdk。 我添加了crypto config和network.json,它描述了我项目目录中的网络节点。 我还将对等地址添加到/etc/hosts文件中。 我在尝试执行此脚本时遇到此问题:

import asyncio
from hfc.fabric import Client

loop = asyncio.get_event_loop()
cli = Client(net_profile="network.json")
org1_admin = cli.get_user('org1.example.com', 'Admin')
cli.new_channel('mychannel')
gopath='/shared/test_notaire/Hyperledger/fabric-samples/first-network/crypto-config'

# Query Peer installed chaincodes, make sure the chaincode is installed
response = loop.run_until_complete(cli.query_installed_chaincodes(
               requestor=org1_admin,
               peers=['peer0.org1.example.com'],
               decode=False
               ))

"""
# An example response:

chaincodes {
  name: "example_cc"
  version: "v1.0"
  path: "github.com/example_cc"
  id: "\374\361\027j(\332\225\367\253\030\242\303U&\356\326\241\2003|\033\266:\314\250\032\254\221L#\006G"
}
"""

# Query Peer Joined channel
response = loop.run_until_complete(cli.query_channels(
               requestor=org1_admin,
               peers=['peer0.org1.example.com'],
               decode=True
               ))

"""
# An example response:

channels {
  channel_id: "channel1"
}
"""

但我得到了这个错误:

Init client with profile=network.json
create org with name=orderer.example.com
create org with name=org1.example.com
create org with name=org2.example.com
create ca with name=ca-org1
create ca with name=ca-org2
Import orderers = dict_keys(['orderer.example.com'])
Import peers = dict_keys(['peer0.org1.example.com', 'peer1.org1.example.com', 'peer0.org2.example.com', 'peer1.org2.example.com'])
New channel with name = mychannel
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    decode=False
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
    return future.result()
  File "/code/hfc/fabric/client.py", line 1618, in query_installed_chaincodes
    responses = await asyncio.gather(*responses)
  File "/usr/local/lib/python3.6/site-packages/aiogrpc/channel.py", line 40, in __call__
    return await fut
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses"
        debug_error_string = "{"created":"@1619428329.913177037","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3940,"referenced_errors":[{"created":"@1619428329.913167398","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":392,"grpc_status":14}]}"

我也无法从容器中ping或nslookup对等点


Tags: tonamecomclientloopasynciocliexample