为什么urllib.urlencode结果加上“25”?

2024-06-02 13:49:32 发布

您现在位置:Python中文网/ 问答频道 /正文

Python代码是:

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

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

为什么25被添加到字符串的末尾?在


Tags: 字符串代码datapasswordurllibprint末尾user
2条回答

来自Wikipedia

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.

简单示例:

>>> urllib.parse.quote('%')
'%25'

%字符在URL中有特殊含义;它用于启动转义序列。请参阅维基百科上的Percent-encoding article。一个文本%也必须被编码,并且%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是一个编码的%字符。在

相关问题 更多 >