Following is the code block that is working as expected.
for key in context:
if isinstance(context[key],collections.Iterable):
queryString += '%s=%s&' % (key, urllib.quote(context[key]))
else:
queryString += '%s=%s&' % (key, context[key])
return queryString
But I did not understand the use of if block. Shouldn’t the following work?
for key in context:
queryString += '%s=%s&' % (key, context[key])
return queryString
It is basically saying “quote anything that isn’t numeric or a sequence when converting to a string representation”. It escapes characters to make them urlencoded.
The
ifwill prevent it from quotingint,float, etc, because those would crash thequotefunction.Though it only makes sense depending on what your potential inputs could be (the value of context). It would crash on say, a list of ints.
Not using
quotewould look like this:And running the
quoteon everything would result in: