> On 1 Jul 2017, at 9:04 PM, Marcus Märker <[email protected]> wrote:
> 
> Hi
> 
> I'm not sure if this is a mod_wsgi issue or a misconfiguration but I'm 
> running out of ideas so I thought I ask here.
> When I post data to an endpoint of my flask application it seems that unicode 
> characters (umlauts in this case) are being escaped with \\, which makes the 
> data unusable.
> 
> The code:
> @app.route('/', methods=['POST'])
> def handle_post():
>     raw_data = request.get_data()
>     data = request.get_json()
>     app.logger.debug('%s\n%s', raw_data, data)
>     return str(data)

As a general rule, you should not just use str() to convert bytes to a unicode 
string. This is because it will use the default system encoding, which may not 
be want you want.

You should at least use:

    data.decode('UTF-8')

I would though suggest you look up how to have Flask understand you are 
returning bytes, as the conversion to unicode is unnecessary as Flask will have 
to convert it back to bytes anyway.

> 
> The command I use:
> curl -X POST -H 'Content-type: application/json' -d '{"text":"test 123 äöü"}' 
> 127.0.0.1:3080
> 
> wsgi file:
> WSGIDaemonProcess wsgi-app user=www-data group=www-data threads=5        
> WSGIScriptAlias / /var/www/wsgi-app/app.wsgi
> 
> <Directory /home/marcus/app>
>     WSGIProcessGroup wsgi-app
>     WSGIApplicationGroup %{GLOBAL}
>     Order deny,allow
>     Allow from all
> </Directory>
> 
> Log output:
> [Sat Jul 01 12:38:22.863316 2017] [wsgi:error] [pid 12045] b'{"text":"test 
> 123 \\xc3\\xa4\\xc3\\xb6\\xc3\\xbc"}'
> [Sat Jul 01 12:38:22.863319 2017] [wsgi:error] [pid 12045] {'text': 'test 123 
> \xc3\xa4\xc3\xb6\xc3\xbc'}
> 
> Environment:
> Ubuntu Server 16.04 LTS, Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2

This is also an old and out of date mod_wsgi version. I would recommend you 
update to the latest. Ubuntu does not support the mod_wsgi packages they ship 
and I can't help you with such an out of date version if there are problems 
with it.

Graham

> 
> Any ideas what the problem could be?
> 
> Marcus
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/modwsgi 
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to