For a little more than a month, I have been writing a simple app with Django to manage the client files in my company, I have Deepin operating syst...
For further actions, you may consider blocking this person and/or reporting abuse
Hi Dennis, you're not giving much info so it's hard to help by just reading your post. You have to make it easy for people to help you :D
Did you save a backtrace? What kind of error are you having? What version of each library are you using? Which problems did you have with cairocffi? Did you try to check their github (especially the closed issues) to see if anyone had your same error?
You mention you switched from WeasyPrint to xhtml2pdf, where does it show the encoding error? Can you isolate it to a reproducible example? What's "unsupported type" error?
Maybe you just have to install compatible libraries in your container.
Anyhow, start from the beginning: you need an error backtrace (or traceback in Python) and a list of packages with versions :D
Yes, this is the traceback error when i use xhtml2pdf view:
UnicodeEncodeError at /generatepdf
'latin-1' codec can't encode character '\ufeff' in position 0: ordinal not in range(256)
Request Method: GET
Request URL: 127.0.0.1:8000/generatepdf
Django Version: 2.0.6
Exception Type: UnicodeEncodeError
Exception Value:
'latin-1' codec can't encode character '\ufeff' in position 0: ordinal not in range(256)
Exception Location: /home/dcruz/PycharmProjects/Clientes/misclientes/utils.py in render_to_pdf, line 12
Python Executable: /usr/bin/python3
Python Version: 3.6.5
Python Path:
['/home/dcruz/PycharmProjects/Clientes',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/dcruz/.local/lib/python3.6/site-packages',
'/usr/local/lib/python3.6/dist-packages',
'/usr/local/lib/python3.6/dist-packages/Django-2.0.6-py3.6.egg',
'/usr/local/lib/python3.6/dist-packages/django_templated_email-2.3.0-py3.6.egg',
'/usr/local/lib/python3.6/dist-packages/django_render_block-0.5-py3.6.egg',
'/usr/lib/python3/dist-packages']
Server time: Sáb, 20 Abr 2019 14:46:22 -0400
Unicode error hint
The string that could not be encoded/decoded was: <ht
I think there is a rare character at the first position that makes the error.. :S
So, the error is telling you something. I don't know what you're encoding nor I can see the code you're writing but the error as you guessed means the first character is outside
latin-1.According to the search engine
\ufeffis the byte order mark.You should try to encode the text with UTF-8:
I think you're doing something wrong with encoding/decoding the text before you transform it.
Can you show me how are you opening the source file? Also check what encoding does it have on disk:
Im saving the html file as utf-8 right now and there is another error.
Environment:
Request Method: GET
Request URL: 127.0.0.1:8000/generatepdf
Django Version: 2.0.6
Python Version: 3.6.5
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'misclientes.apps.MisclientesConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/usr/local/lib/python3.6/dist-packages/Django-2.0.6-py3.6.egg/django/core/handlers/exception.py" in inner
File "/usr/local/lib/python3.6/dist-packages/Django-2.0.6-py3.6.egg/django/core/handlers/base.py" in _get_response
File "/usr/local/lib/python3.6/dist-packages/Django-2.0.6-py3.6.egg/django/core/handlers/base.py" in _get_response
File "/usr/local/lib/python3.6/dist-packages/Django-2.0.6-py3.6.egg/django/views/generic/base.py" in view
File "/usr/local/lib/python3.6/dist-packages/Django-2.0.6-py3.6.egg/django/views/generic/base.py" in dispatch
File "/home/dcruz/PycharmProjects/Clientes/misclientes/views.py" in get
File "/home/dcruz/PycharmProjects/Clientes/misclientes/utils.py" in render_to_pdf
File "/home/dcruz/.local/lib/python3.6/site-packages/xhtml2pdf/document.py" in pisaDocument
File "/home/dcruz/.local/lib/python3.6/site-packages/xhtml2pdf/document.py" in pisaStory
File "/home/dcruz/.local/lib/python3.6/site-packages/xhtml2pdf/parser.py" in pisaParser
File "/home/dcruz/.local/lib/python3.6/site-packages/xhtml2pdf/context.py" in parseCSS
File "/home/dcruz/.local/lib/python3.6/site-packages/xhtml2pdf/w3c/cssParser.py" in parse
File "/home/dcruz/.local/lib/python3.6/site-packages/xhtml2pdf/w3c/cssParser.py" in _parseStylesheet
File "/home/dcruz/.local/lib/python3.6/site-packages/xhtml2pdf/w3c/cssParser.py" in _parseAtKeyword
File "/home/dcruz/.local/lib/python3.6/site-packages/xhtml2pdf/w3c/cssParser.py" in _parseAtPage
Exception Type: TypeError at /generatepdf
Exception Value: 'NotImplementedType' object is not iterable
NotImplementedType object is not iterable.. and there is all :(
Here is my utils.py code: (pretty the same as the manual example)
from io import BytesIO
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None
I don't know how to use markdown sorry for the unformatted thing
What version of
xhtml2pdfare you using ?I the docs you can see an example, but in your shared code I dont see nothing like that example.
Maybe you use this guide, in that case you need to set the correct encondig because by default the library take this based from the HTML header data, something like this:
But if your HTML file is UTF8 you need to encode that and pass the correct encoding argument to
pisaDocument.I'm using xhtml2pdf version 0.2.3.
Still getting
NotImplementedType object its not iterableThis gonna make me crazy guys..