gpt4 book ai didi

python - 为什么 urllib.urlencode 将 "25"附加到结果?

转载 作者:行者123 更新时间:2023-11-28 20:41:12 24 4
gpt4 key购买 nike

Python代码是:

user = "aabc" 
password = "yyy12%"
data = urllib.urlencode({"loginname": user, "nloginpwd": password})
print data

结果是:loginname=aabc&nloginpwd=yyy12%25

为什么要在字符串末尾添加 25

最佳答案

% 字符在 URL 中具有特殊含义;它用于启动转义序列。查看Percent-encoding article在维基百科上。 literal % 也必须进行编码,%25 是编码后的版本。来自维基百科页面:

Because the percent ("%") character serves as the indicator for percent-encoded octets, it must be percent-encoded as "%25" for that octet to be used as data within a URI.

换句话说,%25 是一个编码的 % 字符。

关于python - 为什么 urllib.urlencode 将 "25"附加到结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34002871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com