from urllib.parse import urlencode
print(urlencode('中文'))
运行报错:TypeError: not a valid non-string sequence or mapping object
分析:urllib.urlencode(params)
中的params
需要为字典对象,而传入的是string类型
解决方案:修改传入参数类型,就可以正常使用了
from urllib.parse import urlencode
print(urlencode({'data':'中文'}))
运行结果:data=%E4%B8%AD%E6%96%87