【发布时间】:2018-10-09 18:13:55
【问题描述】:
我正在使用 python 请求库进行以下调用:
response = requests.post(
'https://blockchain-starter.eu-gb.bluemix.net/api/v1/networks/<network id>/chaincode/install',
headers={
'accept': 'application/json',
'content-type': 'multipart/form-data',
'authorization': 'Basic ' + b64encode(credential['key'] + ":" + credential['secret'])
},
data={
'chaincode_id': chaincode_id,
'chaincode_version': new_version,
'chaincode_type': chaincode_type,
'files': open('chaincode.zip', 'rb')
}
)
但是,当我拨打电话时,我收到 500 内部服务器错误(API 是 this,尤其是 Peers / Install Chaincode)。鉴于我之前对其中一个 GET 端点的调用工作正常,我认为我的请求有问题,有人可以帮忙吗?
更新:
解决方案是删除 content-type 标头并将文件上传移动到它自己的 files 参数中:
response = requests.post(
https://blockchain-starter.eu-gb.bluemix.net/api/v1/networks/<network id>/chaincode/install,
headers={
'accept': 'application/json',
'authorization': 'Basic ' + b64encode(credential['key'] + ":" + credential['secret'])
},
data={
'chaincode_id': chaincode_id,
'chaincode_version': new_version,
'chaincode_type': chaincode_language
},
files={
'file': open('chaincode_id.zip', 'rb')
}
)
【问题讨论】:
-
this 有帮助吗?
-
是的!不是第一个答案,而是第二个答案。对于任何感兴趣的人,解决方案是删除
content-type标头并将文件移动到它自己的部分。
标签: python python-2.7 python-requests ibm-cloud ibm-blockchain