0

I am receiving the following error when trying to use pbcopy to add the output to the clipboard. I tried different variations of the command and still no luck. Does anyone have any ideas where I may have failed?

Error Screenshot:

enter image description here

#!/usr/bin/env python3
# This script creates a secure password using all available key combinations.

import secrets , string, os

def prRed(skk): print("\033[91m {}\033[00m" .format(skk))

chars = string.ascii_letters+string.punctuation+string.digits # Cleaner way of assigning variable

print()
pwd_length = int(input('Enter the length of the desired password: '))

print()
print('[+] ' + 'Your secure password is:')
print()

for n in range(1):
    output = ""
    for i in range(pwd_length):
        next_index = secrets.SystemRandom().randrange(len(chars))
        output = output + chars[next_index]
    prRed(os.system("echo '%s' | pbcopy" % output))
print()
Amir Shabani
  • 3,857
  • 6
  • 30
  • 67
Howie B
  • 21
  • 3
  • You have included `string.punctuation` in allowable characters which may have let a closing `'` into your password that you echo inside `'`. – Mark Setchell May 25 '19 at 07:03
  • Thank you, I ended up manually assigning the string.punctuation to exclude quotes. However, instead of cheating, Id like to learn how to include punctuation in a way that doesn't break the pbcopy code, can this be done a different way? – Howie B May 28 '19 at 03:58
  • I really wouldn't recommend using many punctuation characters in a password to be honest - maybe just dash and underscore - firstly because different apps have different allowable characters and secondly because they'll cause you hassle when you try and use them on command-line to mount shares, login to servers and generally parsing things... – Mark Setchell May 28 '19 at 06:52

0 Answers0