简体   繁体   中英

How do I add characters to an encoded string? Python

I need to send a request from the backend I'm doing in Python to an API via URL.

The method requests.get(URL) automatically makes the respective encoding to UTF-8.

The problem is that the API page, when they are special characters, such as in Russian, German, Spanish, etc.... in the address goes the parameter (query, for example) and it is already sent encoded.

For example, the Russian word "Бавария Мюнхен" in UTF-8 becomes:

"%D0%91%D0%B0%D0%B2%D0%B0%D1%80%D0%B8%D1%8F%20%D0%9C%D1%8E%D0%BD%D1%85%D0%B5%D0%BD"

but it turns out that the url when entering manually from the website, to each % adds a 25, that is, it remains as %25 plus the letter that follows in the query encoded.

在此处输入图片说明在此处输入图片说明

The website is RSS Dog .

Questions:

  • How do I manually add that "%25"?
  • Is a coding method that does that in Python.

Translated with www.DeepL.com/Translator :v

The method in python that does it is urllib.quote and urllib.unquote .

%25 is equal to % when unquoted, so you could unquote the entire string, insert them, and then reinsert them if you wanted, but it seems like you're accidentally double quoting the querystring.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM