基于python3.6.1版本,在一个.py文件中,加入这3行:
import requests, re, sys
reload(sys)
sys.setdefaultencoding("utf-8")

出现这样的错误:
sys.setdefaultencoding("utf-8")
AttributeError: module 'sys' has no attribute 'setdefaultencoding'

原因分析:
Python3字符串默认编码unicode, 所以sys.setdefaultencoding也不存在了

解决:
去掉,sys.setdefaultencoding
---------------------
作者:琦彦
来源:CSDN
原文:https://blog.csdn.net/fly910905/article/details/74922378
版权声明:本文为博主原创文章,转载请附上博文链接!

(转)Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding的更多相关文章

  1. Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding'

    基于python3.6.1版本,在一个.py文件中,加入这3行: import requests, re, sys reload(sys) sys.setdefaultencoding("u ...

  2. python reload(sys)找不到,name 'reload' is not defined和Python3异常-AttributeError: module 'sys' has no att

    基于python3.6.1版本,在一个.py文件中,加入这3行:import requests, re, sysreload(sys)sys.setdefaultencoding("utf- ...

  3. python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?

    python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...

  4. python3中报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'

    reload(sys) sys.setdefaultencoding("utf-8") f = open('.\\24.novel.txt','rb') str = f.read( ...

  5. Python AttributeError: module 'sys' has no attribute 'setdefaultencoding'

    Python 3 与 Python 2 有很大的区别,其中Python 3 系统默认使用的就是utf-8编码. 所以,对于使用的是Python 3 的情况,就不需要sys.setdefaultenco ...

  6. AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'

    /*************************************************************************** * AttributeError: 'modu ...

  7. AttributeError: module 'enum' has no attribute 'IntFlag'

    Mac PyCharm新建以Python3.6.1为解释器的Django项目的时候出现以下错误提示: AttributeError: module 'enum' has no attribute 'I ...

  8. Python 3.6安装yaml时报"AttributeError: module 'pip' has no attribute 'main'"和“Non-zero exit code”错误

    1.Python 3.6安装yaml时一开始报AttributeError: module 'pip' has no attribute错误,根据网上提供的解决方法修改Pycharm安装目录D:\Pr ...

  9. AttributeError: 'module' object has no attribute 'main'

    本机环境:ubuntu16.04,  ros-kinetic $ roscore 报错 Traceback (most recent call last): File , in <module& ...

随机推荐

  1. 多表关联解决数据在MVC显示

    由于子表的某些字段是父表的外键,正常情况之下,显示的只是一个键值.如下图的Highlight列,如果这样显示,确实不友好. 如果是在创建或是编辑的模式之下,我们可以使用下拉菜单来解决,如<Htm ...

  2. Spring Security(一)

    Spring Security(一) 基本原理 前言 Spring Security核心功能 认证(你是谁) 授权(你能干什么) 攻击防护(防止伪造身份) Srping Security基本原理 项目 ...

  3. Activity正确获取View宽高

    在View的measure完成后,一般可以通过getMeasureWidth/getMeasureWidth方法可以正确的获取View的宽高,而在特殊情况下,可能需要多次measure才能确定最终的测 ...

  4. POJ1222(SummerTrainingDay01-E)

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11078   Accepted: 7 ...

  5. python学习之老男孩python全栈第九期_day005知识点总结

    1. 数据类型划分: (1) 不可变数据类型(可哈希): 元组, bool, int(123 就是123,不会变成其他数), str, 字典的keys (2) 可变数据类型(不可哈希): 列表list ...

  6. layui实现复选框全选,反选

    html <div class="layui-input-inline"> <input type="checkbox" class=&quo ...

  7. JPEG/PNG/GIF图片格式简析

    JPEG/PNG/GIF是Web浏览器广泛支持的3种图片格式. 1.JPEG格式最适合保存照片和其他复杂图像. 2.GIF和PNG格式最适合保存logo和其他包含单色.线条.文本的简单图形. 3.JP ...

  8. Linux  释放Linux 系统预留的硬盘空间

    释放 Linux 系统预留的硬盘空间 by:授客 QQ:1033553122   大多数文件系统都会保留一部分空间作为紧急情况时用(比如硬盘空间满了),这样能保证有些关键应用(比如数据库)在硬盘满的时 ...

  9. 从零自学Java-6.使用循环重复执行操作

    1.使用for循环: 2.使用while循环: 3.使用do-while循环: 4.提早退出循环(break,continue): 5.为循环命名. 程序Nines:显示1-200的整数与9的乘积 p ...

  10. LeetCode题解之 Increasing Order Search Tree

    1.题目描述 2/问题分析 利用中序遍历,然后重新构造树. 3.代码 TreeNode* increasingBST(TreeNode* root) { if (root == NULL) retur ...