python3:AttributeError: module 'urllib' has no attribute 'quote'
2018-02-11 13:28
2231 查看
python2 与python3版本不兼容的问题真是让人诟病,现在又报错了,我的错误信息为:
Traceback (most recent call last):
File "/Users/eric/Documents/pythonFiles/aliyunxiaomi/chatwithxiaomi/chatwithali.py", line 22, in <module>
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.parse
def percentEncode(str):
res = urllib.parse.quote(str, '')
res = res.replace('+', '%20')
res = res.replace('*', '%2A')
res = res.replace('%7E', '~')
return res
这样就不包错误了。
Traceback (most recent call last):
File "/Users/eric/Documents/pythonFiles/aliyunxiaomi/chatwithxiaomi/chatwithali.py", line 22, in <module>
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.parse
def 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相关文章推荐
- Python3.x中出现 "AttributeError: module 'urllib' has no attribute 'urlopen'" 的解决方法
- AttributeError: module 'tensorflow.python.platform.flags' has no attribute 'mark_flag_as_required'
- python 报错信息: AttributeError: module 'token' has no attribute '__all__'
- python爬虫框架scarpy之AttributeError: module 'scrapy' has no attribute 'spider'
- python大坑:AttributeError: 'module' object has no attribute 'Workbook'
- python3.6脚本import json模块后,报错:AttributeError: module 'json' has no attribute 'dumps'
- python3.6 出现AttributeError: module 'urllib' has no attribute 'urlopen'
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- [Python]attributeError:'module' object has no attribute 'dump'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python 3.x中导入urllib出现AttributeError: module 'urllib' has no attribute 'urlopen'
- 【Python 脚本报错】AttributeError:'module' has no attribute 'xxx'的解决方法
- Python中module 'urllib' has no attribute 'openurl'问题
- python 错误解析 AttributeError: 'module' object has no attribute 'dumps'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 【python学习笔记(2)】脚本报错"AttributeError: 'module' object has no attribute 'xxx'"解决方法
- Python3.6 报错AttributeError: module 'urllib' has no attribute 'Request'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- AttributeError: module object has no attribute “Series”. Code works in Python
- Python脚本报错AttributeError: ‘module’ object has no attribute ’urllibopen'(Python 2.7.11 )