[Fixed]-XML2PDF Throwing Exception while URL starts with /

1πŸ‘

βœ…

The real problem finally revealed it self as mime type problem when I dig into it.

I found the problem when I check all steps. In a step, xml2pdf try to find mime type of the file, and it looks like Python 2.7.6 has no mime type description for .ttf file

>>> from mimetypes import MimeTypes
>>> import urllib 
>>> url = urllib.pathname2url('static/fonts/Arial.ttf')
>>> mime = MimeTypes()
>>> mime_type = mime.guess_type(url)
>>> print mime_type
(None, None)
>>> url = urllib.pathname2url('wsgi.py')
>>> mime_type = mime.guess_type(url)
>>> print mime_type
('text/x-python', None)

I append the lines below to function to correct problem:

import mimetypes
mimetypes.add_type('application/font-ttf', '.ttf')
πŸ‘€Sencer H.

Leave a comment