这两个错误是相关连的python2、python3的兼容错误。

sd=bytes(“abc1\ndone”, encoding=‘utf-8’);
bytes类在python3,有如下的构造方式,如果第一个参数是string的话,后续还要带着参数encoding。这个错误的意思就是缺少encoding参数。
class bytes(object)
| bytes(iterable_of_ints) -> bytes
| bytes(string, encoding[, errors]) -> bytes
| bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
| bytes(int) -> bytes object of size given by the parameter initialized with null bytes
| bytes() -> empty bytes object

如果,在python2执行这个语句错误是:str() takes at most 1 argument (2 given),参数多了
sd=bytes(“newPMTL1Job 1\ndone”, encoding=‘utf-8’);

>>> sd=bytes("abc 1\ndone", encoding='utf-8');
Traceback (most recent call last):File "<stdin>", line 1, in <module>
TypeError: str() takes at most 1 argument (2 given)

下面是python2里的定义,bytes其实是str的一个别名。
class str(basestring)
| str(object=’’) -> string
|
| Return a nice string representation of the object.
| If the argument is a string, the return value is the same object.

python:错误:TypeError: string argument without an encoding;str() takes at most 1 argument相关推荐

  1. Python错误:TypeError: string indices must be integers

    在项目遇到一个错误 : TypeError: string indices must be integers 由于是返回的接口数据,所以一时也分辨不出是哪里的错,然后我就还原了这样的场景: unico ...

  2. Python错误 TypeError: ‘NoneType‘ object is not subscriptable解决方案汇总

    目录 前言 一.引发错误来源 二.解决方案 2-1.解决方案一(检查变量) 2-2.解决方案二(使用 [] 而不是 None) 2-3.解决方案三(设置默认值) 2-4.解决方案四(使用异常处理) 2 ...

  3. python错误:TypeError: Cannot interpret ‘3‘ as a data type

    下面错误: 错误:无法将3当作一个数据类型,那么我们可以知道肯定是缺少了参数,查看np.ones的参数如下: 改为这样就可以了: c = np.ones((2,3,4))

  4. Python 错误:TypeError String Indices Must be Integers 【已解决】

    Python 错误:TypeError String Indices Must be Integers [已解决] 如果你尝试使用字符串值,而不是整数值来访问字典或可迭代对象的值,那么你将收到以下错误 ...

  5. python提示错误TypeError: write() argument must be str, not bytes

    还是在学习<Machine Learning in Action>中决策树一章中,在学习决策树存储过程中先是提示错误TypeError: write() argument must be ...

  6. Python Socket TypeError: a bytes-like object is required, not 'str' 错误提示

    <python核心编程>第三版,发现示例2-1代码返回错误-..纠结很久  发现这里python3.5和Python2.7在套接字返回值解码上有区别.  先介绍一下 python byte ...

  7. Python错误集锦:打开文件路径提示参数无效,OSError: [Errno 22] Invalid argument: ‘D:\juzicode\桔子code\readme.txt’

    原文链接:http://www.juzicode.com/archives/2493 错误提示: 打开文件路径提示参数无效:OSError: [Errno 22] Invalid argument: ...

  8. python之解析 yaml配置文件时TypeError: string indices must be integers

    #定义一个SuperLogin登录函数,传递3个形参数 def SuperLogin(lANIP,username, password):driver = webdriver.Chrome()driv ...

  9. python提示错误TypeError: 'dict_keys' object does not support indexing

    python提示错误TypeError: 'dict_keys' object does not support indexing 原因:python2与python3之间的差异 python2中形如 ...

最新文章

  1. 十四、进程互斥的硬件实现方法
  2. [leetcode]Jump Game
  3. Think in Java之斐波那契数列
  4. 【官方搭建入门】JEECG 平台开发环境搭建必读
  5. javascript常用对象
  6. VK Cup 2012 Round 1 D. Distance in Tree (树形dp)
  7. C++ std::multiset 删除 查找 重复元素中的特定元素
  8. android mac 调试,Mac下使用Android studio真机调试
  9. 验证世界各地区手机号码libphonenumber
  10. java编译器eclipse_java编译器eclipse
  11. Python3制作网易云音乐下载器
  12. 在线编辑word文档
  13. 用dnspod进行DNS解析出错的解决方案
  14. 软件测试中的版本控制
  15. 微信公众号基于 baidu API接口的图像识别
  16. COF多孔复合材料3D-KSC-COFs/ZnO-CdS-Co-Fe2O4/COF-PS-GMA/MW-CNTs-TpPa-COF
  17. 【数学有什么用处?看完后恍然大悟!】
  18. Invalid project description.错误原因分析与解决方案
  19. 6款开发必备的Chrome谷歌浏览器扩展(部分火狐、edge浏览器商店也可以用)
  20. 盲盒商城系统创业是怎么一回事儿?

热门文章

  1. 2的一百万次方 用计算机算,1M换算:计算机里,单位里1.大家都知道数字1M=10^6对吧(M=Million),以10为底,6次方 2.计算机里1...
  2. linux - Visual Studio Code 的安装与卸载
  3. 【转】初探计算机视觉的三个源头、兼谈人工智能
  4. 老男孩mysql运维dba实战21部完整版_老男孩MySQL DBA 运维课程全套,资源教程下载...
  5. 华为 oj java题库_华为OJ题目:刷题
  6. 名编辑电子杂志大师教程 | 如何直接输出安卓apk格式?
  7. K-近邻算法预测电影类型
  8. 常见错误1 定义形参和实参不匹配错误
  9. 中国彩妆行业营销现状分析与投资机会研究报告2022版
  10. 讲个故事给你听,觉得好的带回家!