I have this trouble: I'm working in a script for Blender, that takes an text who comes from a URL and make a 3D object of the text.
This text could be written in any language for example: Spanish, English, Russian, Arabic, Chinese, others...
And for have in mind, the Python that comes with Blender, doesn't have all libraries, in particular doesn't have urllib. Also I can't install any external libraries.
So I copied and pasted the unquote function in my code to transform the text. And here started the troubles.
For example if I get:
'Hello%20World' after the unquote I get 'Hello World' and it's fine.
But if the text is:
'%C3%A1%20%C3%A9%20%C3%AD%20%C3%B3%20%C3%BA'
After the unquote is 'á é à ó úá é à ó ú' And what I wanted is : 'á é í ó ú'
And finally if I have this text:
'%D9%86%D9%86%D8%AA%D9%8A%D9%84%D8%AA%D9%8A%D8%A8%D9%88%D8%AA'
Which is decoded into 'ÙÙØªÙÙØªÙØ¨ÙØªÙÙØªÙÙØªÙØ¨ÙØª', but I expect: 'ننتيلتيبوت'
As far as I researched, the problem is the encoding of the string, because if I do this:
userText = unquote('%C3%A1%20%C3%A9%20%C3%AD%20%C3%B3%20%C3%BA').encode('latin-1').decode('utf-8')
The string is converted correctly and I get : 'á é í ó ú'. But in the case the text be arabic, this doesn't work.
And I didn't figure out what's it's the correctly encode for Arabic text, because those that appear en encoding python documentation didn't worked.
Anyway the problem it's more general, because I don't have chances to know how is the text, I only have the part of the url where the text lies.
The curious fact is that hardcoding the string in any type of text in my code, works properly.
So, anyone knows a way to properly encode and decode this URL to a string in the right way ?
Thanks,
Gonza.