[reportlab-users] Writing to stdout
Robin Becker
robin at reportlab.com
Sun Feb 28 14:58:01 EST 2021
I think this is almost the right answer Christof, but since PDF is not a textual file format I think the correct way to
overcome the python3 encode everything is to use the buffer directly eg
sys.stdout.buffer is a binary file
see https://docs.python.org/3.9/glossary.html#term-binary-file
so rob you should use
c = canvas.Canvas(sys.stdout.buffer)
On 28/02/2021 18:40, Christoph Zwerschke wrote:
> On 28.02.2021 18:55, Rob Allen wrote:
> > This is what happens when I run it:
> >
> > ...
> > TypeError: write() argument must be str, not bytes
>
>
> This is probably because stdout is expecting text (native strings), but ReportLab sends bytes.
>
> It may work when replacing sys.stdout with something like TextIOWrapper(sys.stdout.buffer, encoding='utf8').
>
> -- Christoph
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> https://pairlist2.pair.net/mailman/listinfo/reportlab-users
--
Robin Becker
More information about the reportlab-users
mailing list