Was trying some simple code practice with pyperclip from "Automate boring stuff with Python" book, but I keep running in to the below error when trying to run the program with the command line.
Have tried looking all over the web to no avail: I have tried reinstalling pyperclip with pip command line, copy the init.py file to main Python folder and change file name to pyperclip, but nothing worked so far. Would really appreciate your support in understanding what the problem is here and how to solve it.
Error is as follows:
Traceback (most recent call last):
File C:\Users\AppData\Local\Programs\Python\Python36-32\pw.py, line 15, in <module>
pyperclip.copy(PASSWORD[account])
File C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyperclip\_init_.py", line 424, in copy_windows
count = wcslen(text) + 1
File C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyperclip\_init_.py", line 304, in_call_
ret = self.f(*args)
ctypes.ArgumentError: argument 1: <class 'TYpeError'>: wrong type
The code is as follows:
#! 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 requires a string to be copied and appears to raise TypeError if you try to copy an integer.
Your password dictionary can contain anything so I'd suggest changing the line
pyperclip.copy(PASSWORD[account])
to something like
pyperclip.copy(str(PASSWORD[account]))