string argument expected, got 'bytes'
See original GitHub issueWhen I try to create a PDF, I get the error “string argument expected, got 'bytes”.
I am using the djangoproject demo on Python 3.5 and am running the pre of xhtml2pdf as instructed in the readme.
The error happens when the following line is reached, which is line 35
pdf = pisa.CreatePDF(
StringIO(request.POST["data"]),
result
)
More specifically, it seems that the “result” variable on line 37 is not actually a String variable, but rather a Bytes (or so seen by the code). When I run a type() on “result” it returns <class '_io.StringIO'>
which seems that it should be correct but is still erroring out.
Django is also highlighting line 183 of the document.py file as to where this error is happening which contains the following:
context.dest.write(data) # TODO: context.dest is a tempfile as well...
Is there any workaround that has been found for this or even a known reason as to why it’s happening?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:10 (1 by maintainers)
Top GitHub Comments
I’ve solved the issue. Changing line 13 to the following seems to fix the issue:
and changing line 34 to the following:
Any further thoughts on this? It is blocking for me and the fix above isn’t helping. Here’s a traceback (inline css in template)-