id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 3432,django.test.client.Client.post doesn't like unicode data,Simon Willison,Adrian Holovaty,"Ran in to a weird bug today involving passing a unicode dictionary to the post() method of django.test.client.Client. It was pretty tough to reproduce (it seems you need to post, then get, then post with the same client instance) but I've attached a test case that demonstrates the error. Here's the failing test method: {{{ def test_post_get_post_unicode(self): client = Client() data = { u'firstname': u'Test', u'lastname': u'Example', u'email': u'test@example.com', } keys = data.keys() keys.sort() response = client.post('/echomethod/', data) self.assertEqual(response.content, 'POST\n%s' % ','.join(keys)) response = client.get('/echomethod/') self.assert_(response.content.startswith('GET')) response = client.post('/echomethod/', data) self.assertEqual(response.content, 'POST\n%s' % ','.join(keys)) }}} And the corresponding view: {{{ def echo_view(self, request): from django.http import HttpResponse response = HttpResponse() response.write(request.method + '\n') keys = request.POST.keys() keys.sort() response.write(','.join(keys)) return response }}} And the test output: {{{ ====================================================================== FAIL: test_post_get_post_unicode (__main__.TestPostGetPost) ---------------------------------------------------------------------- Traceback (most recent call last): File ""test_client_unicode.py"", line 85, in test_post_get_post_unicode self.assertEqual(response.content, 'POST\n%s' % ','.join(keys)) AssertionError: 'POST\n' != u'POST\nemail,firstname,lastname' ---------------------------------------------------------------------- }}} Basically, while request.method is still 'POST' the request.POST dictionary doesn't get populated. The workaround is to only post regular dictionaries (without unicode values) to the client.post method. It would be nice if the client either threw an error when passed unicode data or converted it to utf-8 or whatever was most sensible before continuing to process it.",,closed,Core (Other),dev,,fixed,test testclient unicode-branch,,Accepted,0,0,0,0,0,0