当我尝试比较python中的两个字符串时,我在python中得到错误的结果

nav*_*nam 0 python string comparison

当我比较两个字符串时,为什么我得到错误的结果.

if password==en_pass:
            log.info("##### client credentials are OK ####")
else:
     print "credentials are wrong "
Run Code Online (Sandbox Code Playgroud)

我得到的结果是在else块中

这是我的日志消息:

got the password :bmF2ZWVu  , encoded password :bmF2ZWVu
Run Code Online (Sandbox Code Playgroud)

编码密码来自哪里base64,就是我通过在base 64模块中使用encodestring方法得到的.

gef*_*fei 6

似乎密码不是'bmF2ZWVu',但包含尾随空格,如'bmF2ZWVu '.尝试if password.strip()==en_pass.strip()

  • @usernaveen他的意思是密码后面有一些空格字符. (2认同)