基于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. DataTable数据显示于MVC应用程序

    这篇博文是把DataTable的数据显示于MVC的应用程序上. 首先我们在数据库中创建一个表,并添加数据,然后创建存储过程: 接下来,我们去下载一个BusinessBase组件:http://www. ...

  2. Hadoop集群动态服役新的数据节点&&退役数据节点

    备注:新添的机器为hadoop05,现有hadoop01.hadoop02.hadoop03.hadoop04 环境准备: 1.先克隆一台和集群中一样的机器 2.修改机器ip和主机名称 3.删除原来的 ...

  3. MySQL常用操作汇编

    熟悉 我熟悉xxx,其实很多原来熟悉到能背的,如果长时间不用了几乎也就忘了.此时再说自己熟悉XXX就被认为是在吹牛B了,感觉不是很好.所谓温故而知新,对于天资不聪颖的,就是要在一遍一遍的复习实践中慢慢 ...

  4. JS中深浅拷贝 函数封装代码

    一.了解 基本数据类型保存在栈内存中,按值访问,引用数据类型保存在堆内存中,按址访问. 二.浅拷贝 浅拷贝只是复制了指向某个对象的指针,而不是复制对象本身,新旧对象其实是同一内存地址的数据,修改其中一 ...

  5. PDO中的事务处理

    基本原理和步骤其实都是一样的(可参看上一篇“MySQL的事务处理”),PDO中的事务处理就是调用PDO对象的三个方法: 开启事务:beginTransaction 回滚操作:rollBack 执行操作 ...

  6. 使用ThinkPHP实现附件上传

    刚学的使用ThinkPHP框架简单上传附件(图片,文档,视频等文件) 首先需要了解tp框架中Upload.class.php(ThinkPHP/Library/Think/Upload,class,p ...

  7. List中Add()与AddAll()的区别

    我们在开发过程中经常会使用到List<Object> list=new ArrrayList<>(); 这个集合,Object 也可以是String.Integer等. 当我们 ...

  8. Oracle中Merge的使用

    MERGE INTO products p USING product_changes pc ON (p.product_id = pc.product_id) WHEN MATCHED THEN - ...

  9. Ubuntu16.04.2 LTS下使用编译安装程序(使用configure、make、 make install)

    以安装vim为例. (vim 是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面). 1.获取源文件 首先进入/usr/local下(只是为了方便处理安装文件,位置随意) 用git ...

  10. Java:基本数据类型与类型转换

    相关内容: 基本数据类型 整型 浮点型 字符型 布尔型 数据类型转换 数组 首发时间:2017-06-22 21:18 修改时间: 2018-03-16 15:40  :修改了一下文字布局和样式,增加 ...