#!/usr/bin/python
import sys, os, hashlib
import bencode
def main():
# Open torrent file
torrent_file = open(sys.argv[1], "rb")
metainfo = bencode.bdecode(torrent_file.read())
info = metainfo['info']
print(hashlib.sha1(bencode.bencode(info)).hexdigest())
if __name__ == "__main__":
main()
同样的代码,python2可以通过,python3报错。
报错的信息如下:
Traceback (most recent call last):
File "testtr.txt", line 14, in <module>
main()
File "testtr.txt", line 9, in main
metainfo = bencode.bdecode(torrent_file.read())
File "d:\python37\Lib\site-packages\bencode.py", line 68, in bdecode
BTL.BTFailure: not a valid bencoded string
如何解决?
--
FROM 116.231.60.*