*@Jisson Varghese Thank you very much it worked completely fine now*

On Tuesday, February 1, 2022 at 11:39:22 PM UTC+5:30 jis...@gmail.com wrote:

> Check whether FileResponse instead of StreamingHttpResponse helps to solve 
> the issue , 
> https://docs.djangoproject.com/en/4.0/ref/request-response/#fileresponse-objects
>
> On Tue, Feb 1, 2022 at 11:26 PM Aadil Rashid <aadil1...@gmail.com> wrote:
>
>> I am trying to generating pdf from webpages, using popen , but when i 
>> call this
>> view it generates UnicodeDecodeError: 'utf-8' codec can't decode byte 
>> 0xd3 in position 10: invalid continuation byte 
>>
>> This is my view
>> from projName.settings import BASE_DIR
>> from subprocess import Popen, PIPE, STDOUT
>> from wsgiref.util import FileWrapper
>> from django.http import StreamingHttpResponse
>>
>> class DownloadAsPDF(View):
>> def post(self, request, *args, **kwargs): 
>> base = str(BASE_DIR)
>> file_name = str( base + '/testreport.pdf')
>> post_url = request.POST.get("page_url")
>> url = str('http://' + request.get_host() + post_url)
>> chrome_args = ['/path/google-chrome', '--headless', 
>> '--virtual-time-buget=20000',
>> '--print-to-pdf=/path/testreport.pdf', url]
>> external_process = Popen(chrome_args, stdout=PIPE, stderr=STDOUT) 
>> external_process.wait()
>> return_file = FileWrapper(open('{}'.format(file_name), 'r'))
>> download_file_name = 'report'
>> response = StreamingHttpResponse(return_file, 
>> content_type='application/force-download')
>> response['Content-Disposition'] = f'attachment; filename= 
>> {download_file_name}.pdf' 
>> return response
>>
>>
>> Can please anybody, tell me why is it generating this error and what is 
>> the possible solution 
>> this problem, Thanks you very much
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/9a0b68e5-a587-4ac4-a018-a8fcc18f1cf4n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/9a0b68e5-a587-4ac4-a018-a8fcc18f1cf4n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> *Jisson Varghese*
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4bf19bc2-9d5d-476f-952f-f06a5220036bn%40googlegroups.com.

Reply via email to