python-pdfkit icon indicating copy to clipboard operation
python-pdfkit copied to clipboard

Don't use assert to determine python version

Open mpyatishev opened this issue 3 years ago • 1 comments
trafficstars

I have faced with a problem with asserts: we are using PYTHONOPTIMIZE=2 on production environment so all asserts are cleaned from the execution (https://docs.python.org/3/using/cmdline.html#cmdoption-O). As the result, we getting the exception:

/opt/venv/lib/python3.9/site-packages/pdfkit/source.py in to_s(self)
     52         # and cant later encode properly, this is a workaround for this.
     53         # See issue #42
---> 54         if isinstance(self.source, unicode):
     55             return self.source
     56         else:

NameError: name 'unicode' is not defined

I would suggest to use something like sys.version to determine python versions.

mpyatishev avatar Jan 26 '22 07:01 mpyatishev

Hey, how are you? Thank you so much for this bug report. Ive been googling for hours why I got that error as it didnt have any sense to me. I was so damn desesperate that I started reading here and I luckly saw your post.

I hope they fix it! I had to disable PYTHONOPTIMIZE in order for this to stop happening.

If anyone is using Django, you need to do this in settings.py: os.environ["PYTHONOPTIMIZE"] = ""

tomasserravento avatar Oct 25 '22 03:10 tomasserravento