我在将多个变量传递到python urllib模块中时遇到一些问题。
from urllib.parse import quote_plus as urlquote
PASS='test1'
FAIL='test2'
VAR1 = ('test1:%s' % (urlquote((PASS))))
#VAR2 = ('%s:%s' % (urlquote((FAIL,FAIL))))
print(VAR1)
#print(VAR2)
当我在注释VAR2
变量的情况下按原样运行脚本时,得到的预期结果是
test:test1
不幸的是,当我在未注释VAR2
行的情况下运行它时,出现以下错误
TypeError: quote_from_bytes() expected bytes
预期结果应该是
test1:test1
test2:test2
答案 0 :(得分:1)
我知道了
from urllib.parse import quote_plus as urlquote
PASS='test1'
FAIL='test2'
VAR1 = ('test1:%s' % (urlquote(PASS)))
VAR2 = ('%s:%s' % (urlquote(FAIL),urlquote(FAIL)))
print(VAR1)
print(VAR2)