【发布时间】:2012-09-02 20:40:50
【问题描述】:
这是我当前的代码:
encodedstring = base64.encodestring(b"admin:password")[:-1]
现在我想为用户名和密码使用变量,像这样?
username = "admin"
password = "password"
user_pass = username + ":" + password
user_pass = b"user_pass <<<<?
encodedstring = base64.encodestring(user_pass)[:-1]
我该怎么做?
非常感谢
【问题讨论】:
-
bytes(user_pass, 'ascii')不做吗?还是user_pass.encode('ascii')?选择你喜欢的任何编码。 -
是的,bytes(user_pass, 'ascii') 做同样的伎俩。谢谢。
标签: python-3.x base64 byte