Myluzh Blog

Strive to become a dream architect.

python脚本实现RouterOS软路由中文编码转换,RouterOS使用中文备注

发布时间: 2021-12-31 文章作者: myluzh 分类名称: RouterOS


用的就是url gb2313编码

import urllib
from urllib import parse


def url_gb2312(t_type, text):
   if t_type == "encode":
       text = urllib.parse.quote(text.encode('gb2312'))
       text = text.replace("%", "\\")
       return text
   if t_type == "decode":
       text = text.replace("\\", "%")
       text = urllib.parse.unquote(text, encoding='gb2312')
       return text


# 编码
t = url_gb2312("encode", "哈哈哈")
print(t)  # 输出 \B9\FE\B9\FE\B9\FE
# 解码
t = url_gb2312("decode", "\B9\FE\B9\FE\B9\FE")
print(t)  # 输出 哈哈哈

标签: python routeros 中文

发表评论