From e7c3e4c5acdf9a229e13502e14a39caac332fe6c Mon Sep 17 00:00:00 2001 From: Pedro Worcel Date: Sun, 30 Mar 2014 20:58:47 +1300 Subject: [PATCH] Change error into awesome user-friendlyness Hi there, I was getting a very weird error "ODict valuelist should be lists", when attempting to add a header. My code was as followed: ``` msg.headers["API-Key"] = new_headers["API-Key"] 42 msg.headers["API-Sign"] = new_headers["API-Sign"] ``` In the end, that was because there could be multiple equal headers. In order to cater to that, it you guys might enjoy the patch I attach, for it converts strings automatically into lists of multiple headers. I think it should work, but I haven't tested it :$ It'd allow me to have the above code, instead of this one below: ``` msg.headers["API-Key"] = [new_headers["API-Key"]] 42 msg.headers["API-Sign"] = [new_headers["API-Sign"]] ``` --- netlib/odict.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/netlib/odict.py b/netlib/odict.py index 46b74e8eb..d0ff5cf64 100644 --- a/netlib/odict.py +++ b/netlib/odict.py @@ -60,7 +60,9 @@ class ODict: key, they are cleared. """ if isinstance(valuelist, basestring): - raise ValueError("ODict valuelist should be lists.") + # convert the string into a single element list. + valuelist = [valuelist] + new = self._filter_lst(k, self.lst) for i in valuelist: new.append([k, i])