私はPython 3を使用してstdinからファイルのmd5ハッシュを計算しようとしていますPython 3 stdin上のファイルからmd5ハッシュを生成する方法は?
ここにエラーメッセージが返されます。なぜそれがmd5ハッシュを返さないのかわかりません。どんな助けもありがたい。
$./pymd5.py < tmp.pdf
Traceback (most recent call last):
File "./pymd5.py", line 29, in <module>
main()
File "./pymd5.py", line 25, in main
print(m.hexdigest())
TypeError: 'str' does not support the buffer interface
$
コード:
#!/usr/local/bin/python3.2
import sys
import hashlib
BUFSIZE = 4096
def make_streams_binary():
sys.stdin = sys.stdin.detach()
sys.stdout = sys.stdout.detach()
def main():
make_streams_binary()
m = hashlib.md5()
while True:
data = sys.stdin.read(BUFSIZE)
if not data:
break
m.update(data)
print(m.hexdigest())
if __name__ == "__main__":
main()
[TypeError: 'str'はバッファインターフェイスをサポートしていません](http://stackoverflow.com/questions/5471158/typeerror-str-does-not-support-the-buffer-interface) – agf
I申し訳ありませんが、実際問題が何であるか説明していません。 –