Skip to content

Instantly share code, notes, and snippets.

def gen_user_psw(auth):
from urllib import quote
returned = ''
if auth:
# urllib.quote 转义 @:/ 等特殊字符
# 第二个参数表示转义任何字符,默认会不转义 / 字符
user = quote(auth['username'], '')
psw = quote(auth['password'], '')
returned = '%s:%s@' % (user, psw)
return returned