ERROR 程序出错,错误原因:'bytes' object has no attribute 'read'
使用json解析数据时,通常遇到这里就会出现问题'bytes' object has no attribute 'read',这是由于使用的json内置函数不同,一个是load另一个是loads。
import urllib.request
import json response = 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
ERROR 程序出错,错误原因:'bytes' object has no attribute 'read'的更多相关文章
- pyqt(二) 创建第一个程序(helloworld)解决object has no attribute 'setCentralWidget'
1.运行Qt Creator QtCreator主界面分为了6个模式:欢迎模式.编辑模式.设计模式.Debug调试模式.项目模式和帮助模式,分别由左侧的6个图标进行切换,对应的快捷键是Ctrl + 数 ...
- python 错误AttributeError: 'module' object has no attribute 'AF_INET'
写了一个简单的python socket的程序.运行时,报错如下 原因:文件的命名与Python的function的命名冲突 修改名称后,发现还是无法运行,检查目录下面是否有 这样子的一个文件,删除即 ...
- python调用对象属性出错:AttributeError: 'function' object has no attribute '_name_'
出错如下图所示: 原来是因为把__name__写成_name_, 下图为正确结果:
- AttributeError: 'bytes' object has no attribute 'hex'
python3.5之前bytes数据没有hex()属性 需要使用 ''.join(map(lambda x:('' if len(hex(x))>=4 else '/x0')+hex(x)[2: ...
- python3错误AttributeError: 'TestSequenceFunctions' object has no attribute 'seq'
对比了两段代码发现,原来是setUp要用用大写才能被正确引用. 修改后,代码运行成功.
- 'Service' object has no attribute 'process'
在使用selenium+phantomjs时,运行总是出现错误信息: 'Service' object has no attribute 'process' 出现该错误的原因是未能找到可执行程序&qu ...
- AttributeError: 'WebElement' object has no attribute 'send_keys'
这个是没问题的代码:用来打开谷歌搜索cheese并退出 from selenium import webdriver from selenium.common.exceptions import Ti ...
- error C2220: 警告被视为错误 - 没有生成“object”文件
原文:error C2220: 警告被视为错误 - 没有生成"object"文件 这种错误的原因是:原因是该文件的代码页为英文,而我们系统中的代码页为中文. 解决方案: 1. ...
- [Android Studio导入第三方类库方法] Error:(19, 23) 错误: 程序包org.apache.http不存在
本文主要参考以下链接: http://m.blog.csdn.net/blog/BoxRice/48575027 https://drakeet.me/android-studio http://ww ...
随机推荐
- linux 命令 --if
if else-if else 语法格式: if condition1 then command1 elif condition2 then command2 else commandN fi 例如: ...
- 在嵌入式设计中使用MicroBlaze(Vivado版本)
原文Xilinx官方文档<ug898-vivado-embedded-design>第三章 一.MicroBlaze处理器设计介绍(略) 二.创建带有MicroBlaze处理器的IP设计 ...
- 201621123005《Java程序设计》第九次实验总结
201621123005<Java程序设计>第九周实验总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 ...
- Javascript实现重力弹跳拖拽运动效果
声明: By:GenialX 个人主页:胡旭博客 - www.ihuxu.com QQ:2252065614 演示地址: http://www.ihuxu.com/project/gcdmove/ 调 ...
- 作业要求20181023-4 Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 02
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284] 版本控制:https://git.coding.net/liuyy08 ...
- fiddler手机端抓包配置
首先,你得安装fiddler,这是前提条件,手机抓包有必须条件: 需要保持电脑和手机在同一个局域网中 (这一点,我一般会在电脑上启动一个wifi,然后手机连接即可) 下面说一下如何配置: 手机连接电脑 ...
- HDU 2323
http://acm.hdu.edu.cn/showproblem.php?pid=2323 把六边形抽象成坐标进行dp,抽象出的坐标关系必须满足六边形之间的关系.很有趣的一道dp #include ...
- Linux 环境下 javac 编译错误: 编码UTF8的不可映射字符 (编码UTF8/GBK的不可映射字符)
Linux 系统下一般默认使用UTF-8编码, 使用javac 编辑使用其他编码格式编写的源吗时,会出现 “ 错误: 编码UTF8的不可映射字符 ”. 最近在使用 javac 编译 一个在wind ...
- spring-security-4 (5)spring security Java配置实现自定义表单认证与授权
前面三篇讲解了spring security的搭建以及简单的表单认证与授权原理.本篇将实现我们自定义的表单登录与认证. 本篇不会再讲项目的搭建过程,因为跟第二节的搭建如出一辙.本篇也不会将项目中所有 ...
- CSS 中文字体的英文名称 (simhei, simsun) 宋体 微软雅黑等
Mac OS的一些: 华文细黑:STHeiti Light [STXihei] 华文黑体:STHeiti 华文楷体:STKaiti 华文宋体:STSong 华文仿宋:STFangsong 俪黑 P ...