Это код, который я пробую внутри функции Azure с помощью HTTP-триггера.
Код: Выделить всё
import gnupg
import tempfile
import subprocess
import azure.functions as func
import logging
@app.route(route="PGPOne")
def PGPOne(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
# Correctly obtaining the GPG binary path
gpg_path = r'C:\PGPD\dependencies\gpg.exe'
# Testing the GPG binary works
result = subprocess.run([gpg_path, '--version'], capture_output=True, text=True)
print(result.stdout)
# Creating a temporary directory for GPG home
temp_dir = tempfile.mkdtemp()
print(f"Temporary GPG home directory: {temp_dir}")
# Initializing GPG with the temporary home directory
gpg = gnupg.GPG(homedir=temp_dir, binary=gpg_path)
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
Код: Выделить всё
Temporary directory: C:\Users\\AppData\Local\Temp\tmpxacvv8_i
GPG binary path: C:\PGPD\dependencies\gpg.exe
Код: Выделить всё
gnupg.GPG(homedir=temp_dir, binary=gpg_path)
Код: Выделить всё
Python HTTP trigger function processed a request.
[2024-03-18T04:13:19.620Z] Creating directory: C:\PGPD\'C:\Users\\AppData\Local\Temp\tmpxacvv8_i'
[2024-03-18T04:13:19.658Z] [WinError 123] The filename, directory name, or volume label syntax is incorrect: "C:\\PGPD\\'C:"
Код: Выделить всё
C:\PGPD\'
Это при локальной отладке функции с использованием Function Основные инструменты и использование Python 3.10 в настройке виртуальной среды в VS Code.
И я включил двоичную зависимость GnuPG в структуру папок кода, как рекомендовано документацией Microsoft.
Подробнее здесь: https://stackoverflow.com/questions/781 ... invocation