python bytes和str两种类型转换的函数encode(),decode()

  • str通过encode()方法可以编码为指定的bytes
  • 反过来,如果我们从网络或磁盘上读取了字节流,那么读到的数据就是bytes。要把bytes变为str,就需要用decode()方法

例如:

date=“12345”  #str类型

date.encode()  #转换为bytes类型

TypeError: a bytes-like object is required, not 'str'的更多相关文章

  1. python3 TypeError: a bytes-like object is required, not 'str'

    在学习<Python web开发学习实录>时, 例11-1: # !/usr/bin/env python # coding=utf-8 import socket sock = sock ...

  2. 【爬坑】Python 3.6 在 Socket 编程时出现类型错误 TypeError: a bytes-like object is required, not 'str'

    1. 问题描述 Python 3.6 在 Socket 编程时出现错误如下 Traceback (most recent call last): File "F:/share/IdeaPro ...

  3. TCP客户端和服务器间传输数据遇到的TypeError: a bytes-like object is required, not 'str'问题

    使用python实现python核心编程3第472页和474页的TCP时间戳服务器和客户端服务器间数据传输编程时遇到TypeError: a bytes-like object is required ...

  4. moviepy执行TextClip.search方法时报错TypeError: a bytes-like object is required, not str

    ☞ ░ 前往老猿Python博文目录 ░ 执行TextClip.search方法时,报错: >>> from moviepy.editor import * >>> ...

  5. python问题:TypeError: a bytes-like object is required, not 'str'

    源程序: import socket target_host = "www.baidu.com" # 127.0.0.1 target_port = 80 # 建立一个socket ...

  6. linux下运行python3出现TypeError: a bytes-like object is required, not 'str'

    目标:用python将中文存入csv,且中文正常显示. 环境:linux,python3 百度N久,方法都不行或是比较复杂. 以上代码用python3运行后,出现TypeError: a bytes- ...

  7. sbt package报错:a bytes-like object is required, not 'str'

    Traceback (most recent call last): File , in <module> s.sendall(content) TypeError: a bytes-li ...

  8. python中MySQL模块TypeError: %d format: a number is required, not str异常解决

    转载自:http://www.codeif.com/topic/896 python代码: attr_sql = "INSERT INTO `ym_attribute` (`attr_nam ...

  9. python 3.5: TypeError: a bytes-like object is required, not 'str'

    出现该错误往往是通过open()函数打开文本文件时,使用了'rb'属性,如:fileHandle=open(filename,'rb'),则此时是通过二进制方式打开文件的,所以在后面处理时如果使用了s ...

随机推荐

  1. 在web项目启动时,执行某个方法

    在web项目中有很多时候需要在项目启动时就执行一些方法,而且只需要执行一次,比如:加载解析自定义的配置文件.初始化数据库信息等等,在项目启动时就直接执行一些方法,可以减少很多繁琐的操作. 在工作中遇到 ...

  2. 开发一个项目之css

    background属性 5+3 image,color,position,repeat,attachment size: 保持纵横比 contain 再发大就cover了 clip:背景绘制区域 b ...

  3. 【作业3.0】HansBug的第三次博客规格总结

    转眼间第三次作业了,似乎需要说点啥,那就说点. 规格&工业 说到这个,不得不提一下软件开发的发展史. 历史的进程 早在上世纪50年代,就已经有早期的编程语言出现,也开始有一些程序编写者出现(多 ...

  4. 获取iframe 内容

    parent.$.find("iframe")[0].contentWindow.getvalue(); h.find("iframe")[0].content ...

  5. HDOJ 6508 Problem I. Spell Boost (01背包/DP)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6508 题目: Problem Description Shadowverse is a funny car ...

  6. JAVA学习笔记(4)—— 排序算法

    排序,就是使一串记录,按照其中的某个或某些关键字的大小,递增或递减的排列起来的操作.排序算法,就是如何使得记录按照要求排列的方法. 排序算法大体可分为两种: 一种是比较排序,时间复杂度O(nlogn) ...

  7. Appnium-API-Status

    Status Java:// TODO Python:selenium.webdriver.common.utils.is_url_connectable(port) Description Retu ...

  8. linux系统自动备份打包部署脚本

    1.使用jenkins配置任务 2.执行脚本放在/home/guard/目录下 #!/bin/sh #author wangxiangyu #当前时间 DATE=$(date +%Y%m%d) #环境 ...

  9. Day 18: 记filebeat内存泄漏问题分析及调优

    ELK 从发布5.0之后加入了beats套件之后,就改名叫做elastic stack了.beats是一组轻量级的软件,给我们提供了简便,快捷的方式来实时收集.丰富更多的数据用以支撑我们的分析.但由于 ...

  10. JIRA API 对接

    系统要跟JIRA对接,将本系统数据发送给jira. 开始一头雾水怎么让数据传过去已什么形式存在,是存数据库呢还是怎么显示呢.研究半天发现其实只要将原数据作为json数据提供给jira接口,jira接口 ...