How to convert HTTP query to UTF-8?

I’m able to get any HTTP GET/POST query, However, only in ASCII mode.
When I entered the text áaa@bbb.cc’ in an input field, I got at my server the text ‘aaa%40bbb.cc’. Apparently I have to convert the text ‘%40’ into ‘@’ via chr(int(‘40’, 16)).
But what about the text ‘украї́нська’, because I got at my server the text ‘%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B0’? How can I convert it?

Is this what you need?

from urllib.parse import unquote
url = "%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B0"
print(unquote(url))
1 Like

Go get one of the web application frameworks and use that instead. You have asked a number of questions about low-level HTTP mechanics, and you’re wasting a huge amount of time and effort reimplementing these fundamentals. This is the one that I most often use:

https://flask.palletsprojects.com/en/2.2.x/

and there are a good few others.

1 Like

Concerning using unquote:
I tried it as follows:

  from urllib.parse import unquote
  print(unquote("%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B0"))

But I got the following error message:
UnicodeEncodeError: ‘charmap’ codec can’t encode characters in position 0-6: character maps to

What to do now without using Flask temporarily?

As for Flask, I will still have to study it. After that, I will try it, if I like it.

This is because your terminal either does not support displaying those characters, or is not properly configured to display them. Please see for example Python, Unicode, and the Windows console - Stack Overflow.

Yep! That’s the code I want, because it contains only two statements. It really works perfectly. Thank you very much for your excellent help!

1 Like

You are very welcome; I’m only to happy to help others, where I can.

You have a good day.