Forums

No data shown in the pdf api response from requests module

After receiving the API response it should be shown as a pdf in a new link. The new tab is opening and also pdf is getting loaded but the pdf page is blank no data is visible. check the URL: http://santoshmohan04.pythonanywhere.com/ewbpdf?ewb_numbers=191009260563&gstin=29AAFCD5862R000

The response received has been returned as

response = requests.request("POST", url, headers=headers, data=payload)
data = response.text
response = make_response(data)
response.headers["Content-Type"] = "application/pdf"
return response

What is the url you're hitting? Free accounts have restricted internet access. Maybe add some logging to be sure if data is not empty, that make_response is returning what you're expecting, etc.

I am getting the response data when I am printing data ie. print(data) but after doing make_response the response data is empty. Is there any alternative to make_response or any thing to be changed. The below is the response data which has to be shown as pdf.

%PDF-1.3 %���� 11 0 obj << /Type /ExtGState /ca 1 /CA 1 >> endobj 14 0 obj << /Type /ExtGState /CA 1 >> endobj 10 0 obj << /Type /Page /Parent 1 0 R /MediaBox [0 0 595.28 841.89] /Contents 8 0 R /Resources 9 0 R >> endobj 9 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /ExtGState << /Gs1 11 0 R /Gs2 14 0 R >> /Font << /F1 12 0 R /F2 13 0 R >> /XObject << /I1 5 0 R /I2 6 0 R /I3 7 0 R >> >> endobj 8 0 obj << /Length 3017 /Filter /FlateDecode >> stream x��]ێ�}W����+ ��vb�����İ��OU_8��fke���Asw��u��n��g{����_r`R��ڽ��3���y���������?~��������{�����/~��]}�������������_av��������u����_>��~�d�7��"��xO6��p�~�&���~ �C�����D�w4�����K� >{�)�CS��������!�?v�Wo��;�a�AK����O���?'���~��1���|O?��F��;�5�1���5�9��\�+Y#��N�-M��[#�l�"���������gq%���;]6�� A��۬ 1z��E��fJ@|2���ES�& l ȪH��W �4&n4�l&җn���غ 5PSNlʡ$%_���Hֿ`��AA29�q ����x���TK0Ი��Azj��;3dKIncJhG�3��l��+m䯍#7e<t ��&V?=E���E3!GL3Р%<�!��;��Ĝ��4@846���&n��dd{8��:]��u��y��������p�ͣ��tQ�pAtnO��)���7��`�~k������b��YVk��s`�`"�X♬qL4������!��eym�T�.r�̒I5�؊�=��Q��^h�UV��䫞�u�:Q�w�qȥ4��9C���t�o���(�Zn1[�^��bv��l�ȁ\*����~�����~Kvy�v� �o��| ���30�c��8š��&�Q�8�R�R�/\Lz�3,^��&_�����p=9$����K�̅�����3AvgOزn���غ0�z�y�c�z���yNRa���/��,�7~���j�D�p!.����e��Y���������Mn �>\�Y\��S��\�����jٕ�!� _{�t��%+J����x�W�S� ̛�Ks\3�3�h�FƕM ��q�Zz-�)6>�� $�*�����������8P4щK/��=6O�n�D�D�-�+�&0)��@"i\�E@8�+���j,>��������;k�Yhc��B|+�2s����ykQ~ ���5oM��$��� u}[v�1}͚٠��IK#C��1���q ��t����wt4Q6 ���i5JLs^���*M5H-vϮp��[��PdLܦȘhE ���^dg��AgkXh0M��m[!D$I/%B"��MI\zG%x�d��LiF7g�N�^�E�D'�e�7��'+ ���� 1OA|���`4��h�>bꍫV���Z307��f�i��*���`�IO����z�LL�5lP��[��|6��E��~6~�"=���z$ ��3(��q��G8JA!2����XofƆ|#�;Y���\W1�AFI5'j7ÖJQ��H _ ԧt']sU��΄�Z���Z��hs`�I*M�`���}Bp���ޚu�\�z,��L>o+s����)��g:G��K3�GJ{Զ <��RȠ[�.1{lהFy@-i�xT��2.#�����p c)��wR��PϘ2L5��1 zr���3����3=}Z����gz���t^����=��KXS][J��d V5;/v��N,Jj���U �����|Ԍ)1 ����A��Kpt�� ��"5����X[?�ꗸ���5�{��3`J]����Y�|gpS����������D�����32C ���� �t�O��E(O�7^)�d��$�����Ȇm�ÓE�����X�k�������Z��Nw���>�N�DָR�3�Z! e��c��!zh��n�Q �&��'�l�3���.�}�i{�2��hq0��T3qjL1�x%�~�j"\�[gb=oMXO}��]��`� (9:��28Փ /qd)V%�Y��u,�Mj>D/?qd����������O��v<��aD��09"�ed2D=���/���L��Y�]J(.�WW_��#��>퐸FK6�y^.b�I�$W�������5)'�G_,d�Ɂw �u�cgz�3�k/&��ĝ���JjE�s,��9k8zLo�F��7L ���l�=�I��م;�x�t�\�\?A䚇8�̑�`�)odM�y!{�9�l��G�0&�x09����~*�f�ób��m����/��b��A� B�>�6��|��b2�s��� (T!�ʐ���Y y�>{��P�M*����f����?28�5ga-$�)���A}�v�@L.�L��j)pQ��6 {t�'�8z�03

It looks like the data that you're using in make_response is actually some html with an embed tag. My guess would be that the "PDF" you think you're getting from the URL you're accessing is not actually a PDF, but an HTML page that happens to embed a PDF.

how can i display it as pdf in the browser.

You'd need to get the actual PDF from the site then I believe that your view will work correctly.