使用pyperclip时"Wrong Type"我应该如何解决错误?



正在尝试使用"使用 Python 自动化无聊的东西"一书中的 pyperclip 进行一些简单的代码练习,但是在尝试使用命令行运行程序时,我不断遇到以下错误。

尝试在网络上查找无济于事:我尝试使用 pip 命令行重新安装 pyperclip,将 init.py 文件复制到主 Python 文件夹并将文件名更改为 pyperclip,但到目前为止没有任何效果。非常感谢您在了解这里的问题以及如何解决它方面的支持。

错误如下:

Traceback (most recent call last):
 File C:UsersAppDataLocalProgramsPythonPython36-32pw.py, line 15, in <module>
  pyperclip.copy(PASSWORD[account])
 File C:UsersAppDataLocalProgramsPythonPython36-32libsite-packagespyperclip_init_.py", line 424, in copy_windows
  count = wcslen(text) + 1
 File C:UsersAppDataLocalProgramsPythonPython36-32libsite-packagespyperclip_init_.py", line 304, in_call_
  ret = self.f(*args)
ctypes.ArgumentError: argument 1: <class 'TYpeError'>: wrong type

代码如下:

#! python3
# pw.py - An insecure password locker program
PASSWORD = {'email':1234,'facebook':5678}
import sys, pyperclip
if len(sys.argv) < 2:
    print('Usage: python pw.py [account] - copy account password')
    sys.exit()
account = sys.argv[1] #first command line arg is the account name
if account in PASSWORD:
    pyperclip.copy(PASSWORD[account])
    print('Password for ' + account + ' copied to clipboard')
else:
    print('There is no account named ' + account)

PyperClip 需要复制一个字符串,如果您尝试复制一个整数,它似乎会引发 TypeError。

您的密码字典可以包含任何内容,所以我建议更改该行

pyperclip.copy(PASSWORD[account])

到类似的东西

pyperclip.copy(str(PASSWORD[account]))

相关内容

最新更新