ERROR 程序出错,错误原因:'bytes' object has no attribute 'read'
使用json解析数据时,通常遇到这里就会出现问题'bytes' object has no attribute 'read',这是由于使用的json内置函数不同,一个是load另一个是loads。
import urllib.request import jsonresponse = urllib.request.urlopen('http://www.reddit.com/r/all/top/.json').read() jsonResponse = json.load(response)for child in jsonResponse['data']['children']:print (child['data']['title'])
通常解决方式有两种,一种是更改函数为loads,另一种是更改编码格式为utf8
第一种解决方式:
jsonResponse = json.loads(response.decode('utf-8'))
第二种解决方式
使用json.loads()而不是json.load()
内容参考:https://stackoverflow.com/questions/6541767/python-urllib-error-attributeerror-bytes-object-has-no-attribute-read
转载于:https://www.cnblogs.com/sanduo1314/p/7668144.html
ERROR 程序出错,错误原因:'bytes' object has no attribute 'read'相关推荐
- AttributeError: ‘bytes‘ object has no attribute ‘encode‘异常解决方案
AttributeError: 'bytes' object has no attribute 'encode'是:"字节"对象没有属性的编码的意思. 很明显,是编码格式的问题,例 ...
- paddleocr ‘bytes‘ object has no attribute ‘shape‘
paddleocr 训练reg时报错: paddleocr 'bytes' object has no attribute 'shape' [2022/02/08 21:15:54] root ERR ...
- AttributeError: 'bytes' object has no attribute '__dict__'
今天用python写后台时,在向客户端返回数据时,老是报错: AttributeError: 'bytes' object has no attribute '__dict__' 出错误的地方: js ...
- 使用face_recognition模块:错误AttributeError:'PngStream' object has no attribute 'chunk fcWp'
使用face_recognition模块:错误AttributeError:'PngStream'object has no attribute 'chunk fcWp' 文章目录: 一.错误:Att ...
- 求助!spyder beautifulsoup4显示错误:AttributeError: 'HTMLParserTreeBuilder' object has no attribute 'initia
spyder beautifulsoup4显示错误: AttributeError: 'HTMLParserTreeBuilder' object has no attribute 'initia 实 ...
- pytorch 错误 AttributeError: ‘Tensor‘ object has no attribute ‘backword‘
pytorch 错误 AttributeError: 'Tensor' object has no attribute 'backword' 按错误说明是没有backword属性. 错误代码 loss ...
- provider:SQL Network Interfaces,error:26 - 定位指定的服务器/实例时出错--错误原因及解决办法
问题截图: 错误 错误原因一 未启动SQL服务 错误原因二 数据库和VS自带的LocalDB有冲突: 导致远程过程调用失败:(需要卸载VS中的LocalDB) 方法 解决办法一 启动SQL Serve ...
- python 错误AttributeError: ‘dict_keys‘ object has no attribute ‘sort‘
当运行Python代码时,出现以下错误: AttributeError: 'dict_keys' object has no attribute 'sort' 当代码有sort函数时,检查其他代码都没 ...
- iteritems python3_Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决...
引言 目前Python2和Python3存在版本上的不兼容性,这里将列举dict中的问题之一.下面话不多说,来看看详细的介绍: 1. Python 2 vs python 3 根据Python社区的 ...
最新文章
- python吃内存还是cpu_Python2 得到 CPU 和内存信息要怎么实现呢?
- 【深度学习】使用transformer进行图像分类
- java容器02--ArrayList源码分析
- linux跨版本升级,深度Deepin系统支持跨版本升级
- [C语言 - 10] C语言保留字
- ehcache springboot_Spring Boot 入门示例合集(附源代码)
- 怎么会Sql serverW数据库模型图转化成ord于--您还可以查看属性信息字段
- Sniffer安全技术从入门到精通
- 整理一年中使用到的工具和类库,可能正有你需要的!
- MySoft.Data入门篇:编写业务逻辑
- 综述文章笔记——《A Survey on Traffic Signal Control Methods》等
- 计算机的基本配件图片,计算机硬件的重要部件
- 软件工程 个人学习笔记(第二章)
- nginx正向代理转发https出现502
- 苹果CMS海螺模板V16魔改版2.0修复bug分享给大家
- [RK3588 Android12]删除谷歌搜索框
- Linux汇编----变址寻址与间接寻址
- 如何批量将多个 PDF 文档快速合并成一个文档
- JST日本压着端子PH系列线对板连接器的PCB封装库
- 产品经理的金字塔之旅---将“打杂”的实习经历描述的高大上!!!
热门文章
- 计算机科学速成课18:操作系统
- 记录pageHelper分页orderby的坑
- cmake make
- xib文件的读取方法
- 收到朋友寄来的煎饼了
- powerDesigner需求建模
- idea插件sonar安装使用教程
- org.gjt.mm.mysql.Driver和com.mysql.jdbc.Driver的概述
- JavaScript(一)——变量,数据类型及转换、运算符和逻辑结构
- c ajax传递多个参数,c# – 使用jQuery AJAX将字符串数组传递给具有可变参数数量的webmethod...