我已经在vb.net中安装并手动定位了python解释器,现在当下面的代码运行(执行)时,它会在它的DOS提示符(控制台)上显示一些错误。这是什么意思?但它在Visual Studio VB.net中没有出现任何错误
错误
Traceback (most recent call last):
File "E:\Visual Studio 2012\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 106, in exec_file
exec_code(code, file, global_variables)
File "E:\Visual Studio 2012\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 82, in exec_code
exec(code_obj, global_variables)
File "C:\Users\USERNAME\AppData\Local\Temporary Projects\PythonApplication1\PythonApplication1.py", line 11, in <module>
target_str = target_hexstr.decode('hex')
AttributeError: 'str' object has no attribute 'decode'
Press any key to continue . . .
代码
ver = 2
prev_block = "000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717"
mrkl_root = "871714dcbae6c8193a2bb9b2a69fe1c0440399f38d94b3a0f1b447275a29978a"
time_ = 0x53058b35 # 2014-02-20 04:57:25
bits = 0x19015f53
# https://en.bitcoin.it/wiki/Difficulty
exp = bits >> 24
mant = bits & 0xffffff
target_hexstr = '%064x' % (mant * (1<<(8*(exp - 3))))
target_str = target_hexstr.decode('hex')
nonce = 0
while nonce < 0x100000000:
header = ( struct.pack("<L", ver) + prev_block.decode('hex')[::-1] +
mrkl_root.decode('hex')[::-1] + struct.pack("<LLL", time_, bits, nonce))
hash = hashlib.sha256(hashlib.sha256(header).digest()).digest()
print (nonce, hash[::-1].encode('hex'))
if hash[::-1] < target_str:
print ('success')
break
nonce += 1