Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit 0f71f0e

Browse files
committed
Added a sanitation loop before data keys and values are posted to DocumentCloud that converts them into strings for #106
1 parent 15d4749 commit 0f71f0e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

documentcloud/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,22 @@ def put(self, method, params):
116116
data = params.get("data")
117117
del params['data']
118118
params = urllib.parse.urlencode(params, doseq=True)
119+
# Convert all numeric keys and values into strings
120+
string_data = {}
121+
for key, value in data.items():
122+
if not isinstance(key, six.string_types):
123+
key = str(key)
124+
if not isinstance(value, six.string_types):
125+
value = str(value)
126+
string_data[key] = value
119127
# Format them in the style documentcloud expects
120128
# ?data['foo']=bar&data['tit']=tat
121129
params += "".join([
122130
'&data[%s]=%s' % (
123131
urllib.parse.quote_plus(key.encode("utf-8")),
124132
urllib.parse.quote_plus(value.encode("utf-8"))
125133
) for key, value in
126-
list(data.items())
134+
string_data.items()
127135
])
128136
else:
129137
# Otherwise, we can just use the vanilla urllib prep method

0 commit comments

Comments
 (0)