mapnik / python-mapnik

Python bindings for mapnik
GNU Lesser General Public License v2.1
160 stars 91 forks source link

PDF test fails with python 3 #138

Open tomhughes opened 7 years ago

tomhughes commented 7 years ago

The PDF generation test is failing when run under python 3 with a bytes/string compatibility error:

======================================================================
ERROR: python_tests.pdf_printing_test.test_pdf_printing
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/tom/src/fedora/python-mapnik/python-mapnik-8139e5c7aebc2b555f991fc32f6190a1db1cf405/test/python_tests/pdf_printing_test.py", line 42, in test_pdf_printing
    make_pdf(m, actual_pdf, esri_wkt)
  File "/home/tom/src/fedora/python-mapnik/python-mapnik-8139e5c7aebc2b555f991fc32f6190a1db1cf405/test/python_tests/pdf_printing_test.py", line 30, in make_pdf
    page.finish()
  File "/home/tom/src/fedora/python-mapnik/python-mapnik-8139e5c7aebc2b555f991fc32f6190a1db1cf405/mapnik/printing/__init__.py", line 1115, in finish
    reverse_all_but_last=True)
  File "/home/tom/src/fedora/python-mapnik/python-mapnik-8139e5c7aebc2b555f991fc32f6190a1db1cf405/mapnik/printing/__init__.py", line 1149, in convert_pdf_pages_to_layers
    (properties, ocgs) = self._make_ocg_layers(file_reader, file_writer, output_pdf, layer_names)
  File "/home/tom/src/fedora/python-mapnik/python-mapnik-8139e5c7aebc2b555f991fc32f6190a1db1cf405/mapnik/printing/__init__.py", line 1192, in _make_ocg_layers
    output_pdf.mergePage(page)
  File "/usr/lib/python3.5/site-packages/PyPDF2/pdf.py", line 2210, in mergePage
    self._mergePage(page2)
  File "/usr/lib/python3.5/site-packages/PyPDF2/pdf.py", line 2256, in _mergePage
    page2Content = PageObject._pushPopGS(page2Content, self.pdf)
  File "/usr/lib/python3.5/site-packages/PyPDF2/pdf.py", line 2170, in _pushPopGS
    stream = ContentStream(contents, pdf)
  File "/usr/lib/python3.5/site-packages/PyPDF2/pdf.py", line 2641, in __init__
    data += s.getObject().getData()
TypeError: can't concat bytes to str

----------------------------------------------------------------------
Ran 577 tests in 22.566s

I have to say it's not at all obvious to me from the context is this is a bug in python-mapnik or in PyPDF itself...

winsento commented 6 years ago

+1

winsento commented 6 years ago

@tomhughes you need to install latest PyPDF2. It solve this problem. pip3 install git+https://github.com/mstamy2/PyPDF2.git