The problem is in generating qr code. There are standards of Sberbank on how the line should look and what encoding should be used (windows-1251). https://www.sberbank.ru/common/img/uploaded/files/shtrih-kod-standart.pdf
So, I use django-qr-code or something like that, the qr code is generated and scanned online, but some fields are decoded something like that - УФК РїРѕ РўРѕРјСЃРєРѕР№ РѕР ± Р »Р ° СЃС‚ Ryo
I suspect that I use the wrong encode / decode methods. Python 3.5 is used.
I attach some code:
view.py
def get(self, request, *args, **kwargs): listener = self.get_listener() form = l_f.InvoiceForm(request.GET) if form.is_valid(): customer = listener.customer.get_fio_dict() qr_text = "ST00011|Name=УФК по Томской области (ТГПУ л/с 0000Ы0000)|" \ "PersonalAcc=0000000000|" \ "BankName=Отделение Томск|" \ "BIC=00000000|" \ "CorrespAcc=0|" \ "PayeeINN=000000000|" \ "Category=Образовательные услуги" \ "LastName="+customer['surname']+"|" \ "FirstName="+customer['name']+"|" \ "MiddleName="+customer['father_name']+"|" \ "Contract="+listener.order_number+"|" \ "PayerAddress=ул. Пупкина 22|" \ "Sum=" + str(int(form.cleaned_data['invoice_sum']) * 100) print(qr_text.encode().decode('windows-1251')) context = { 'listener': listener, 'title': 'Квитанция на оплату', 'month': form.cleaned_data['month'], 'invoice_sum': form.cleaned_data['invoice_sum'], 'qr_text': qr_text.encode().decode('windows-1251') # 'bank_sum': form.cleaned_data['bank_sum'] } else: context = {} return render(request, 'docs/templates_of_views/kvitancia.html', context)
encodeordecodedoes not pass the encoding name, then utf-8 will be used. Accordingly,qr_text.encode().decode('windows-1251')encodes the string in utf-8 and immediately decodes it from cp1251 . What is the general sense of callingendodeanddecodein a row? - Sergey Gornostaev 1:21 pm