如何将非ascii字符添加到文件名中?

how to add non-ascii characters into filename?

我在尝试下载 pdf 文件时遇到问题,该文件的文件名中包含俄语单词。我用的是pdfkit工具

def get_pdf_document(request, code):
    host = request.scheme + "://" + request.META["HTTP_HOST"]
    uri = reverse('documents:view_signed_document',
              kwargs={'code': code}) + "?is_pdf=true"
    obj = get_object_or_404(DownloadCode, code=code)
    options = {
        'page-size': 'A4',
        'encoding': "UTF-8",
        'no-outline': None,
        'margin-bottom': '17',
        'margin-left': '10',
        'margin-right': '10',
        'margin-top': '10',
        'footer-html': host + reverse('api:pdf-footer', kwargs={'code': code}),
    }
    if obj.doc_type == ACTS_TYPE or obj.doc_type == LISTS_TYPE:
        options['orientation'] = 'Landscape'
    result = pdfkit.from_url(host + uri, False, options=options)
    response = HttpResponse(result, content_type='application/pdf')
    response[
        'Content-Disposition'] = 'attachment; filename=\"{}-{}.pdf\"'.format(GET_DOC_TYPE[obj.doc_type], code)
    response['Content-Length'] = response.tell()
    return response

我有那些常数变量:

PDF_INVOICE = u"СЧЕТ-ФАКТУРА"
PDF_ACT = u"АКТ"
PDF_LIST = u"НАКЛАДНАЯ"
PDF_PAYMENT = u"СЧЕТ НА ОПЛАТУ"
PDF_RECON = u"АКТ СВЕРКИ"
PDF_COMMON = u"НЕФОРМАЛИЗОВАННЫЙ"


GET_DOC_TYPE = {
    INVOICE_TYPE: PDF_INVOICE,
    ACTS_TYPE: PDF_ACT,
    LISTS_TYPE: PDF_LIST,
    PAYMENTS_TYPE: PDF_PAYMENT,
    RECONS_TYPE: PDF_RECON,
    COMMONS_TYPE: PDF_COMMON,
}

和我的错误信息:

'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

而且我不知道如何解决这个问题。请帮忙

将常量变量编码为utf-8格式

PDF_INVOICE = (u"СЧЕТ-ФАКТУРА").encode('utf-8')