Hi,

On Oct 25, 3:34 pm, "Vlad K." <[email protected]> wrote:
> Hi!
>
> I'm using the WebTest package for functional tests with
> webtest.TestApp(...), providing the POST params as dictionary to
> webtest.TestApp.post(). The values in the dictionary are unicode (u" "
> strings), and the test script has proper encoding given via #-*-
> coding:UTF-8 -*- as first line.
>
> However, the posted data (received by the Pyramid 1.2 app and stored in
> db) has all non-ascii chars replaced with ????. There is no error
> thrown. I tried forcing use_unicode=True to TestApp, but still the same,
> also added content_type = "application/x-www-form-urlencoded;
> charset=UTF-8", and tried even recoding all values with
> .encode("UTF-8"). To no avail.
>
> How can I use WebTest.TestApp.post() to post unicode data?
>

The problem is that WebTest use urlencode to encode the params:

>>> urlencode({'data': u'd\xe9d\xe9'}, doseq=True)
'data=d%3Fd%3F'

But this is wrong:

>>> unquote('d%3Fd%3F')
'd?d?'

It should work with already encoded data..

>>> unquote(urlencode({'data': u'\xe9'.encode('utf-8')}, doseq=True))
'data=\xc3\xa9'

The solution is to encode the body by yourself. ( post(params=body) )

Can you open an issue on the bitbucket tracker ?
https://bitbucket.org/ianb/webtest/issues?status=new&status=open
I'll try to have a look at this.

Regards,

Gael

> Thanks.
>
> --
>
> .oO V Oo.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to