Message201727
When csv.DictWriter.writerow is fed a dict with extra fieldnames (and extrasaction='raise') and any of those extra fieldnames aren't strings, a TypeError-exception is thrown. To fix the issue; in csv.py, edit the line:
raise ValueError("dict contains fields not in fieldnames: " + ", ".join(wrong_fields))
to:
raise ValueError("dict contains fields not in fieldnames: " + ", ".join(repr(wrong_field) for wrong_field in wrong_fields))
Attached is a patch that fixes the problem (works in both 2.6 and 2.7, I haven't tried anything else).
Here is a simple test to demonstrate the problem:
import cStringIO, csv
sio=cStringIO.StringIO()
writer=csv.DictWriter(sio, ["foo", "bar"])
writer.writerow({1:"hello", 2:"world"}) |
|
Date |
User |
Action |
Args |
2013-10-30 10:59:32 | tomas_grahn | set | recipients:
+ tomas_grahn |
2013-10-30 10:59:32 | tomas_grahn | set | messageid: <1383130772.27.0.178945173135.issue19449@psf.upfronthosting.co.za> |
2013-10-30 10:59:32 | tomas_grahn | link | issue19449 messages |
2013-10-30 10:59:31 | tomas_grahn | create | |
|