Что не так в Django?

Привет!
Проблема
Environment:


Request Method: POST
Request URL: http://192.168.0.107:8000/TSP_app/

Django Version: 3.1.5
Python Version: 3.9.1
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'polls.apps.PollsConfig',
 'accounts',
 'TSP_app',
 'rest_framework',
 'API_TSP',
 'bootstrap5',
 'TSP_server']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/home/ts/Dev/Django/mysite/Django_app/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/ts/Dev/Django/mysite/Django_app/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ts/Dev/Django/mysite/TSP_app/views.py", line 27, in home
    'private_key': gpg.export_keys(key, True, passphrase=passphrase),
  File "/home/ts/Dev/Django/mysite/Django_app/lib/python3.9/site-packages/gnupg.py", line 1306, in export_keys
    self._handle_io(args, f, result, passphrase=passphrase,
  File "/home/ts/Dev/Django/mysite/Django_app/lib/python3.9/site-packages/gnupg.py", line 1028, in _handle_io
    p = self._open_subprocess(args, passphrase is not None)
  File "/home/ts/Dev/Django/mysite/Django_app/lib/python3.9/site-packages/gnupg.py", line 934, in _open_subprocess
    result = Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE,
  File "/usr/lib/python3.9/subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.9/subprocess.py", line 1752, in _execute_child
    self.pid = _posixsubprocess.fork_exec(

Exception Type: TypeError at /TSP_app/
Exception Value: expected str, bytes or os.PathLike object, not GenKey

Код с проблемой:
from django.shortcuts import render
from django.http import JsonResponse
from .forms import create_key_form
import gnupg

gpg = gnupg.GPG()
gpg.encoding = 'utf-8'

def home(request):
    if request.method == 'POST':
        form = create_key_form(request.POST)
        if form.is_valid():
            key_type = form.cleaned_data['key_type']
            key_lenght = form.cleaned_data['key_lenght']

            real_name = form.cleaned_data['real_name']
            comment = form.cleaned_data['comment']
            passphrase = form.cleaned_data['passphrase']

            save_key = form.cleaned_data['save_key']

            input_data = gpg.gen_key_input(key_type=key_type, key_length=key_lenght, name_real=real_name, comment=comment, passphrase=passphrase)
            key = gpg.gen_key(input_data)

            return render(request, 'TSP_app', {
                'have_key': True,
                'private_key': gpg.export_keys(key, True, passphrase=passphrase), # <-- Здесь
                'public_key': gpg.export_keys(key)
            })

    form = create_key_form()

    return render(request, 'TSP_app/home.html', {'form': form})


Спасибо!
  • Вопрос задан
  • 126 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы