That is because response.body_file is https://github.com/Pylons/webob/blob/99890b763dbd441ca1e5f14f8418efa2a8173ab0/src/webob/response.py#L1445 <https://github.com/Pylons/webob/blob/99890b763dbd441ca1e5f14f8418efa2a8173ab0/src/webob/response.py#L1445> which calls https://github.com/Pylons/webob/blob/99890b763dbd441ca1e5f14f8418efa2a8173ab0/src/webob/response.py#L671 <https://github.com/Pylons/webob/blob/99890b763dbd441ca1e5f14f8418efa2a8173ab0/src/webob/response.py#L671> on write.
It does the conversion for you... That's not the same as setting body_file directly on the response, which does NOT go through that same mechanism and instead assumes that the file is a file in binary mode. > On Oct 19, 2020, at 10:23, Mike Orr <sluggos...@gmail.com> wrote: > > On Sun, Oct 18, 2020 at 1:22 PM Bert JW Regeer <xiste...@0x58.com> wrote: >> >> Your body_file is not bytes, but str. You need to make sure that what you >> pass to body_file returns bytes. > > I thought that but 'writer = csv.writer(response.body_file)' works for > me, and my row items are 'str'. In Python 2 I had to convert unicode > to boytes or I'd get an error, but Python 3 accepts 'str' values > directly and the resulting file download is correct. > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pylons-discuss+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pylons-discuss/CAH9f%3DurwVOtKjYweOyzG7YLA%2BQNb_hVG5zrrA2cjRoG%2BQmtB8Q%40mail.gmail.com. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/6BCDEE32-6614-4EA9-B0F2-7E176E54C81D%400x58.com.