2

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.

0

1 Answer 1

1

I figured out, that the problem was work with an outdated urllib.

Recently I tried with the urllib for Python 3 that lies in my computer and worked perfectly. Was my mistake for no checking what I was using.

And I managed to import the parse.py in my code :D

Now I only do userText = parse.unquote(url)

Sign up to request clarification or add additional context in comments.

1 Comment

You should always check for that kind of things @gjg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.