使用gnupg解密gpg文件

时间:2010-07-26 19:56:56

标签: python gnupg encryption

我正在尝试解密我下载的gpg文件中的一些数据。将文件下载到目录是没有问题的,但我实际上在解密它们时遇到了麻烦。这就是我现在正在做的事情:

def extractGPGs(gpglist,path,gpgPath="\"C:\\Program Files\\GNU\\GnuPG\\gpg.exe\""):
os.chdir(path)

if not os.path.isdir("GPGFiles"):
    os.mkdir("GPGFiles")
if not os.path.isdir("OtherFiles"):
    os.mkdir("OtherFiles")

if gpglist == None:
    print "No GPG files found"
    return

try:
    gpg = gnupg.GPG(gpgbinary=gpgPath)
except:
    raise "Path to gpg.exe is bad"

print "Extracting GPG Files..."

for filename in gpglist:       

    print "Extracting %s..." % filename
    stream = open(filename,"rb")
    decrypted_data = gpg.decrypt_file(stream,output=".\\OtherFiles")
    stream.close()

print "Finished Extracting GPG Files"

这是我得到的错误:

Traceback (most recent call last):
File "C:\Documents and Settings\nlesniewski\Desktop\downloadData.py", line 281, in <module>
    main(vendor,category)
  File "C:\Documents and Settings\nlesniewski\Desktop\downloadData.py", line 273, in main
    extractAndParse.main(info['LocalFolder'])
  File "C:\Documents and Settings\nlesniewski\Desktop\extractAndParse.py", line 147, in main
    extractGPGs(getGPGs(getAllArchives(path)),path)
  File "C:\Documents and Settings\nlesniewski\Desktop\extractAndParse.py", line 133, in extractGPGs
    decrypted_data = gpg.decrypt_file(stream,output=".\\OtherFiles")
  File "C:\Python25\Lib\site-packages\gnupg.py", line 574, in decrypt_file
    os.remove(output) # to avoid overwrite confirmation message
WindowsError: [Error 5] Access is denied: '.\\OtherFiles'

为什么我会收到此错误,更重要的是,我如何解密gpg?

1 个答案:

答案 0 :(得分:2)

也许您需要输出为文件名而不是目录。

相关问题