AttributeError: 'module' object has no attribute 'post'问题
2016-09-02 09:26
766 查看
在学习python网页爬虫时,测试requests的post方法进行表单提交时,命名.py文件为requests.py 代码如下:
在运行时,报错:AttributeError: ‘module’ object has no attribute ‘post’
查找资料发现,命名.py脚本时,不能与模块名,预留字同名,若同名,生成的.pyc文件就有问题,导致报错。
解决办法:
首先修改.py脚本的命名,不能与模块名,预留字同名。
修改完成后,还需要删除工程中生成的.pyc文件,因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件。
然后运行,即可成功。
import requests params={'firstname':'xing','lastname':'ming'} r=requests.post("http://pythonscraping.com/files/processing.php",data=params) print r.text
在运行时,报错:AttributeError: ‘module’ object has no attribute ‘post’
查找资料发现,命名.py脚本时,不能与模块名,预留字同名,若同名,生成的.pyc文件就有问题,导致报错。
解决办法:
首先修改.py脚本的命名,不能与模块名,预留字同名。
修改完成后,还需要删除工程中生成的.pyc文件,因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件。
然后运行,即可成功。
相关文章推荐
- AttributeError: 'module' object has no attribute 'face' 问题解决 opencv+python
- 使用旧版本tensorflow出现了negative等报错的问题,AttributeError: 'module' object has no attribute 'xxx'"
- AttributeError: ‘module’ object has no attribute’ 问题
- 【TensorFlow问题】AttributeError:'module' object has no attribute 'mul'
- 解决问题 AttributeError: 'module' object has no attribute 'face_recognition_model_v1'
- AttributeError: ‘module’ object has no attribute’xxx 问题解决
- 【TensorFlow问题】AttributeError:'module' object has no attribute 'mul'
- 【TensorFlow问题】AttributeError:'module' object has no attribute 'mul'
- AttributeError 'module' object has no attribute 'handlers'--Python子模块导入问题
- AttributeError: 'module' object has no attribute 'LabelMap'
- web.py 启动时候出现AttributeError: 'module' object has no attribute 'inet_pton'错误
- 'module' object has no attribute 'MLPRegressor'问题解决(Python2.7)
- AttributeError: 'module' object has no attribute 的解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- Python2.7 安装mock出现AttributeError: 'module' object has no attribute的解决方法
- python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
- web.py 直接使用示例代码,web.application报错, 'module' object has no attribute 'application',问题原因分析
- pygame安装问题(1) 'module' object has no attribute 'init'
- AttributeError: 'module' object has no attribute 'Serial'
- AttributeError: 'module' object has no attribute 'getpass'