1👍
✅
The pdf file is correct (as shown by the correct start and end %PDF-1.4 ... %%EOF
.
There is some errors in your code, I see 2 return
statement in your function. Probably the result of some tests of refactoring.
Also, you aren’t closing your opened file (since the return trigger first), prefer using with
statement for files and let the file opened for the strict minimum of time (open, read, close), you have many things that have nothing to do with the file before reading it.
Finally, I advice running a pep8
check over your code, you will see many errors that will be a problem soon or later (it would have yield the return
problem immediatly).
Source:stackexchange.com