При использовании модуля Python gnupg
я получил эту ошибку "TypeError: argument of type 'GenKey' is not iterable"
.
Я следую этому уроку:
https://www.saltycrane.com/blog/2011/10/python-gnupg-gpg-example/#generate-key
иЯ решил некоторые проблемы с его кодом.Тогда я получил ошибку, которая не может быть решена для меня.
Prepare:
install python-gnupg by `pip install python-gnupg`
(not gnupg because it cause permission error)
I have windows version gnupg installed(solve one previous problem)
and make sure `gpg` is reachable.
Вот основной код, который я использовал:
import gnupg
class FilterGnupg:
# this code follows https://www.saltycrane.com/blog/2011/10/python-gnupg-gpg-example/#generate-key
def __init__(self):
self.gpg = gnupg.GPG()
def generateKey(self, passwd = ''):
if os.path.exists('./data/gpg.asc'):
return
import random, string
if passwd == '':
randkey = ''
for i in range(15):
randkey = randkey + random.choice(string.ascii_lowercase)
# randkey (random 16 bit user passwd)
self.user_key = passwd
else:
self.user_key = passwd
email_header = ''
for i in range(8):
email_header = email_header + random.choice(string.ascii_lowercase)
input_value = self.gpg.gen_key_input(
name_email = '{}@filter.com'.format(email_header)
)
key = self.gpg.gen_key(input_value)
ascii_armored_public_keys = self.gpg.export_keys(key)
ascii_armored_private_keys = self.gpg.export_keys(key, True)
with open('gpg.asc', 'w') as f:
f.write(ascii_armored_public_keys)
f.write(ascii_armored_private_keys)
if __name__ == "__main__":
fg = FilterGnupg()
fg.generateKey()
Когда запустить этот код, появится окно pinentry-qt и просточто ты хочешь.Нажмите ОК,
Traceback (most recent call last):
File "cryptology.py", line 97, in <module>
fg.generateKey()
File "cryptology.py", line 83, in generateKey
ascii_armored_public_keys = self.gpg.export_keys(key)
File "C:\Users\ss\AppData\Local\Programs\Python\Python36\lib\site-packages\gnupg.py", line 1277, in export_keys
p = self._open_subprocess(args)
File "C:\Users\ss\AppData\Local\Programs\Python\Python36\lib\site-packages\gnupg.py", line 923, in _open_subprocess
startupinfo=si)
File "C:\Users\ss\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\ss\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 971, in _sexecute_child
args = list2cmdline(args)
File "C:\Users\ss\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 461, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'GenKey' is not iterable