[Python] Having trouble reading private key (asc) within Azure Python Function

Discussão em 'Python' iniciado por Stack, Janeiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have this piece of Python code in Azure function. Secret.asc file is purely a file with private key, but this code only reads the public key info, no private key info ever gets imported successfully.

    The error keeps saying: gpg: error running '/usr/bin/gpg-agent': exit status 2 gpg: failed to start agent '/usr/bin/gpg-agent': General error gpg: can't connect to the agent: General error gpg: error getting the KEK: No agent running gpg: error reading '[stdin]': No agent running gpg: import from '[stdin]' failed: No agent running gpg: Total number processed: 0 gpg: imported: 1 gpg: secret keys read: 1 [GNUPG:] IMPORT_RES 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0

    #DECRYPTION
    private_key_path = os.path.join("/home/site/wwwroot", "secret.asc")
    encrypted_file_path = os.path.join("/home/site/wwwroot", "Encrypted.txt")
    gpg_home = '/home/site/wwwroot/gpg_home'
    if not os.path.exists(gpg_home):
    os.makedirs(gpg_home)
    gpg = gnupg.GPG(gnupghome=gpg_home,use_agent=False)


    with open(private_key_path, "r") as private_key_file:
    key=gpg.import_keys(private_key_file.read())




    I tried all kinds of things to kick-start agent in the SSH in the Azure function but nothing has worked. please help, thanks!

    Continue reading...

Compartilhe esta Página