2

The Python code is:

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

The result is: loginname=aabc&nloginpwd=yyy12%25

Why was 25 added to the end of the string?

vaultah
  • 44,105
  • 12
  • 114
  • 143
gsky
  • 193
  • 1
  • 10

2 Answers2

4

The % character has special meaning in a URL; it is used to start an escape sequence. See the Percent-encoding article on Wikipedia. A literal % then has to be encoded too, and %25 is the encoded version. From the Wikipedia page:

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.

In other words, the %25 is an encoded % character.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
3

From 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.

Simple example:

>>> urllib.parse.quote('%')
'%25'
vaultah
  • 44,105
  • 12
  • 114
  • 143