Both Reportlab and PikePDF registers "pdfdoc" encodings, which means that which encoding you actually end up using is arbitrary. I guess it depends on the import order, but I haven't checked.
That's all and well in itself, and shouldn't be a problem, but alas, PikePDF's encoding is using the qpdf library, and that library will not tell you which character failed to encode. Therefore, it doesn't raise UnicodeEncodeError which requires that information, but ValueError. This is actually specified in the docs for encode() and decode():
I've made a PR for changing pikepdf's error from ValueError to UnicodeError, but that only fixes half the problem. I believe Reportlab should make one or both of these minor changes:
1. Catch UnicodeErrors instead of UnicodeEncodeErrors/UnicodeDecodeErrors, as this is clearly allowed to be raised by codecs. This should have no drawbacks.
2. Register it's pdfdoc codec under a second internal name, f ex pdfdoc_rl, and use that name, to make sure it's the Reportlab codec that is used. This has the potential drawback that you don't use the PikePDF encoding, which uses qpdflib, and is written in C++ and potentially might be faster, but it increases reliability.
Thoughts on this?
//Lennart