I discovered an issue with our code when generating dynamic CSVs under 
Python3.  I'm hoping someone can point me in the right direction.  I 
couldn't find the appropriate migration/changelog information.  This works 
fine under Python2.

The generic way we create/serve the CSV and check it in tests are below.

The two problems:

1. Under Python3, an exception is thrown under waitress, because of 
attempted string+byte concatenation. 
(https://github.com/Pylons/waitress/blob/master/src/waitress/task.py#L316)

    >    towrite += data + b"\r\n"

    > TypeError: can only concatenate str (not "bytes") to str

2. I picked this up in a unit test; i can't seem to access any sort of 
body/text/content off the response.

    from pyramid.request import Request
    from pyramid import testing

    self.config = config = testing.setUp()
    app = self.config.make_wsgi_app()

    req = Request.blank(csv_link)
    req.remote_addr = "127.0.0.1"
    resp = req.get_response(app)
    self.assertEqual(resp.status_code, 200)
    self.assertTrue(resp.text.startswith("User CPU time,"))



---

 def view_csv(request):
    csvfile = StringIO()
    csvwriter = csv.writer(csvfile)
    for row in ((1, "a"), (2, "b")):
        csvwriter.writerow(row)
    csvfile.seek(0)
    as_csv = Response(content_type="text/csv", body_file=csvfile, 
status=200)
    as_csv.headers["Content-Disposition"] = str("attachment; 
filename=example.csv")
    return as_csv

---






-- 
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/7d3c278f-8d20-4456-b05c-33c8d2cb6a67n%40googlegroups.com.

Reply via email to