python3:AttributeError: module 'urllib' has no attribute 'quote'

网友投稿 1098 2022-10-01

python3:AttributeError: module 'urllib' has no attribute 'quote'

python3:AttributeError: module 'urllib' has no attribute 'quote'

python2 与python3版本不兼容的问题真是让人诟病,现在又报错了,我的错误信息为:

Traceback (most recent call last): File "/Users/eric/Documents/pythonFiles/aliyunxiaomi/chatwithxiaomi/chatwithali.py", line 22, in canstring += '&' + percentEncode(k) + '=' + percentEncode(v) File "/Users/eric/Documents/pythonFiles/aliyunxiaomi/chatwithxiaomi/chatwithali.py", line 14, in percentEncode res = urllib.quote(str.decode(sys.stdin.encoding).encode('utf8'), '')AttributeError: module 'urllib' has no attribute 'quote'

然后,查阅相关资料,我的修改为:

import urllib.parsedef percentEncode(str): res = urllib.parse.quote(str, '') res = res.replace('+', '%20') res = res.replace('*', '%2A') res = res.replace('%7E', '~') return res

这样就不包错误了。

参考文献

[1].Python: Importing urllib.quote.https://stackoverflow.com/questions/31827012/python-importing-urllib-quote

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:公众号预览多长时间失效?(微信公众号预览多久失效)
下一篇:[leetcode] 77. Combinations
相关文章

 发表评论

暂时没有评论,来抢沙发吧~