Python3 没有写入属性?

Python 3 no write attribute?

我有一个错误,下面是部分代码: 其余代码位于 https://github.com/Flajt/Python-Webcam/blob/Flajt-ui-1/ui.py

Traceback (most recent call last):
  File "C:\Users\Flajt\Documents\GitHub\Python-Webcam\ui.py", line 66, in <module>
    create()
  File "C:\Users\Flajt\Documents\GitHub\Python-Webcam\ui.py", line 31, in create
    save2=pickle.dump(password, hash)
TypeError: file must have a 'write' attribute`

代码:

if Pass_ok:
    hash = pbkdf2_sha256.encrypt(password2, rounds=200000, salt_size=16)
    password=open("pass.pkl","wb")
    save2=pickle.dump(password, hash)
    main()

问题很简单,你将两个参数反转为 pickle.dump。顺便说一句,如果可以的话,最好写一个简短的 运行ning 演示脚本。这样其他人就可以轻松 运行 了。这是一个 运行 可行的解决方案,修复

#!/usr/bin/env python3

import pickle
from passlib.hash import pbkdf2_sha256

hash = pbkdf2_sha256.encrypt("foo", rounds=200000, salt_size=16)
with open("pass.pkl", "wb") as password:
    # save2=pickle.dump(password, hash)
    pickle.dump(hash, password)