python - 使用 Python 在 Visual Studio Code 中显示日语字符
问题描述
解决方案
It's called Percent-encoding:
Percent-encoding, also known as URL encoding, is a method to encode arbitrary data in a Uniform Resource Identifier (URI) using only the limited US-ASCII characters legal within a URI.
Apply the unquote
method from urllib.parse
module:
urllib.parse.unquote(string, encoding='utf-8', errors='replace')
Replace
%xx
escapes by their single-character equivalent. The optional encoding and errors parameters specify how to decode percent-encoded sequences into Unicode characters, as accepted by thebytes.decode()
method.
string
must be astr
. Changed in version 3.9:string
parameter supportsbytes
andstr
objects (previously onlystr
).
encoding
defaults to'utf-8'
.errors
defaults to'replace'
, meaning invalid sequences are replaced by a placeholder character.
Example:
from urllib.parse import unquote
encodedUrl = 'JapaneseChars%E3%81%82or%E3%81%B3'
decodedUrl = unquote( encodedUrl )
print( decodedUrl )
JapaneseCharsあorび
One can apply the unquote
method to almost any string, even if already decoded:
print( unquote(decodedUrl) )
JapaneseCharsあorび
推荐阅读
- java - Embedded Jetty:缺少应用程序/json 的 MessageBodyWriter
- reactjs - 通过 AJAX 响应插入 HTML 和 React JS
- javascript - chrome.tabs 未在浏览器控制台中提供输出
- axios - axios拦截器:需要理解javascript代码
- mysql - Django 在具有超过 1000 万条记录的表上进行慢速内连接
- chart.js - 向左旋转图例chartjs
- java - 无法从响应过滤器中抛出错误
- python - 在 Elastic Beanstalk Web 应用程序中安装 Torch 失败
- python - 最短路径的Python QGIS处理
- facebook-messenger-bot - 我的 bottender messneger 机器人在部署后没有在数据库上发布,但它在控制台上工作正常