djago搭建参考:https://www.bilibili.com/read/cv10030536/

成功搭建后加入区块链部分,其中遇到的问题:

1.区块链相关代码:

from django.shortcuts import render, redirectfrom django.contrib import messagesfrom app01 import modelsfrom app01.utils.pagination import Paginationfrom app01.views.sdk.client.bcosclient import BcosClientfrom app01.views.sdk.client.bcoserror import BcosException, BcosErrorfrom app01.views.sdk.client.datatype_parser import DatatypeParserfrom app01.views.sdk.eth_utils import to_checksum_address# 上链开始#materialname = request.POST.get('materialname')# 获取原料名称uid=request.session.get("info")# 获取厂家ID# 从文件加载abi定义abi_file = "D:\\python\\djangoProject6\\app01\\views\\sdk\\contracts\\SimpleInfo.abi"data_parser = DatatypeParser()data_parser.load_abi_file(abi_file)contract_abi = data_parser.contract_abitry:client = BcosClient()# 实例化一个client对象print(client.getinfo())# 部署合约print("\n>>Deploy:----------------------------------------------------------")with open("D:\\python\\djangoProject6\\app01\\views\\sdk\\contracts\\SimpleInfo.bin",'rb') as load_f:contract_bin = load_f.read()load_f.close()result = client.deploy(contract_bin)print("deploy", result)# 发送交易,调用一个改写数据的接口print("\n>>sendRawTransaction:----------------------------------------------------")to_address = result['contractAddress']args = [number, int(uid),to_checksum_address('0x7029c502b4F824d19Bd7921E9cb74Ef92392FB1c')]receipt = client.sendRawTransactionGetReceipt(to_address, contract_abi, "set", args)print("receipt:", receipt)# 调用一下call,获取数据print("\n>>Call:------------------------------------------------------------------------")res = client.call(to_address, contract_abi, "getname")print("call materialname:", res)res = client.call(to_address, contract_abi, "getbalance")print("call factoryid result:", res)except BcosException as e:print("execute demo_transaction failed ,BcosException for: {}".format(e))traceback.print_exc()except BcosError as e:print("execute demo_transaction failed ,BcosError for: {}".format(e))traceback.print_exc()except Exception as e:client.finish()traceback.print_exc()client.finish()# 上链结束

tip:注意路径和要引入的包

2.证书拷贝问题

说是证书配置问题,按照fisco bcos的教程把fisco下的证书文件重新复制的sdk的bin目录下,把bin目录里面的内容删除掉

3.区块链高度应该加2,但是只加1问题:

显示错误是这样的,把grammer.py从刚下的python_sdk中重新拷贝一份,那里文件有问题就重新上传那里,然后会报一些包引用的错误,根据需要改,其中range引入不了,把报错的six.moves删掉成功解决。

tip:

1.进程自动关闭问题参考的nohup:https://blog.csdn.net/weixin_41519463/article/details/89963166?spm=1001.2014.3001.5506

2.启动命令的ip号问题参考3(找不到了,放个截图):

3.已经完成的很好的sdk(仅限自己使用版):

【免费】sdk配置完成自己使用版资源-CSDN文库