Permalink
Browse files

Automatically encode all POST strings in ajax.util's request() functi…

…on, so that urllib.urlencode can parse the characters properly regardless of their encoding
  • Loading branch information...
1 parent 463088c commit fb1a19c1a4fe3056084fda614b938a44146c82d6 @rowenaluk rowenaluk committed with adammck Aug 15, 2010
Showing with 7 additions and 3 deletions.
  1. +7 −3 ajax/utils.py
View
@@ -60,9 +60,13 @@ def request(path, get=None, post=None, encoding=None):
# so let's pretend that it's the django default
else:
encoding = settings.DEFAULT_CHARSET
- data = urllib.urlencode(post)\
- if post is not None else None
-
+ # urlencode only takes bytes, so we need to encode
+ # whatever charset we're using as bytes
+ data = None
+ if post is not None:
+ encoded_post = dict([k, v.encode(encoding)] for k, v in post.items())
+ data = urllib.urlencode(encoded_post)
+
# build the content-type header, including the character set
# that we just encoded the POST data into
headers = {

0 comments on commit fb1a19c

Please sign in to comment.