将多个参数传递给python urllib模块

时间:2019-06-24 17:11:49

标签: python-3.x urllib

我在将多个变量传递到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

1 个答案:

答案 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)