Search code examples
utf-8character-encodinggoogle-apigoogle-appsgoogle-admin-sdk

UTF-8 encoding Google Apps Email Settings API


I've been using Google Apps Email Settings API for a while but I came to a problem when I tried to insert aliases, signatures or any information with "ñ" or "Ñ". It adds garbage instead of those characters and it doesn't seem to respect the charset specified (utf-8) in the HTTP header nor the XML character encoding.

I have tried via my own python code and also using OAuth Playground[1] but it's been impossible to properly add the mentioned characters.

¿Any idea/suggestion?

Thanks in advance.

EDIT: It seems that the problem is not in the request but in the response. I have encoded it successfully in my code but it should be also fixed in OAuth Playground.

[1] https://developers.google.com/oauthplayground/


Solution

  • I have succesfully called Google API client methods using UTF8-encoded strings, so it is definitely an issue with your Python setup.

    I would workaround this issue sending Unicode strings instead of UTF-8 encoded:

    u'literal string' # This is unicode
    'encoded utf-8 string'.decode('utf-8') # This is unicode
    

    EDIT: Re-reading your answer it seems that you are making raw HTTP calls with hand-made XML documents. I can't understand why. If it's the way you want to go, take a look into Emails Settings API client code to learn how to build the XML documents.