[英]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. 我需要通过URL从我在Python中进行的后端向API发送请求。
The method requests.get(URL)
automatically makes the respective encoding to UTF-8. 方法requests.get(URL)
自动将相应的编码转换为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. 问题在于,当API页面是特殊字符(例如俄语,德语,西班牙语等)时,地址中的参数(例如查询)带有参数,并且已经过编码发送。
For example, the Russian word "Бавария Мюнхен" in UTF-8 becomes: 例如,UTF-8中的俄语单词“БаварияМюнхен”变为:
"%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. 但是事实证明,从网站手动输入时,该网址会为每个%添加25,也就是说,它仍为%25加上查询编码后的字母。
The website is RSS Dog . 该网站是RSS Dog 。
Questions: 问题:
Translated with www.DeepL.com/Translator :v 翻译成www.DeepL.com/Translator:v
The method in python that does it is urllib.quote
and urllib.unquote
. python中执行此操作的方法是urllib.quote
和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. %25
在取消引用时等于%
,因此您可以取消引用整个字符串,将它们插入,然后根据需要重新插入它们,但是似乎您不小心在双引号中加上了查询字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.