This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tomas_grahn
Recipients tomas_grahn
Date 2013-10-30.10:59:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1383130772.27.0.178945173135.issue19449@psf.upfronthosting.co.za>
In-reply-to
Content
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"})
History
Date User Action Args
2013-10-30 10:59:32tomas_grahnsetrecipients: + tomas_grahn
2013-10-30 10:59:32tomas_grahnsetmessageid: <1383130772.27.0.178945173135.issue19449@psf.upfronthosting.co.za>
2013-10-30 10:59:32tomas_grahnlinkissue19449 messages
2013-10-30 10:59:31tomas_grahncreate