使用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'的更多相关文章

  1. pyqt(二) 创建第一个程序(helloworld)解决object has no attribute 'setCentralWidget'

    1.运行Qt Creator QtCreator主界面分为了6个模式:欢迎模式.编辑模式.设计模式.Debug调试模式.项目模式和帮助模式,分别由左侧的6个图标进行切换,对应的快捷键是Ctrl + 数 ...

  2. python 错误AttributeError: 'module' object has no attribute 'AF_INET'

    写了一个简单的python socket的程序.运行时,报错如下 原因:文件的命名与Python的function的命名冲突 修改名称后,发现还是无法运行,检查目录下面是否有 这样子的一个文件,删除即 ...

  3. python调用对象属性出错:AttributeError: 'function' object has no attribute '_name_'

    出错如下图所示: 原来是因为把__name__写成_name_, 下图为正确结果:

  4. 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: ...

  5. python3错误AttributeError: 'TestSequenceFunctions' object has no attribute 'seq'

    对比了两段代码发现,原来是setUp要用用大写才能被正确引用. 修改后,代码运行成功.

  6. 'Service' object has no attribute 'process'

    在使用selenium+phantomjs时,运行总是出现错误信息: 'Service' object has no attribute 'process' 出现该错误的原因是未能找到可执行程序&qu ...

  7. AttributeError: 'WebElement' object has no attribute 'send_keys'

    这个是没问题的代码:用来打开谷歌搜索cheese并退出 from selenium import webdriver from selenium.common.exceptions import Ti ...

  8. error C2220: 警告被视为错误 - 没有生成“object”文件

    原文:error C2220: 警告被视为错误 - 没有生成"object"文件 这种错误的原因是:原因是该文件的代码页为英文,而我们系统中的代码页为中文.   解决方案: 1. ...

  9. [Android Studio导入第三方类库方法] Error:(19, 23) 错误: 程序包org.apache.http不存在

    本文主要参考以下链接: http://m.blog.csdn.net/blog/BoxRice/48575027 https://drakeet.me/android-studio http://ww ...

随机推荐

  1. poj 3744 概率dp 快速幂 注意排序 难度:2

    /* Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5304   Accepted: 1455 De ...

  2. npm设置仓库

    如果国外官方的npm仓库下载速度很慢的话,可以考虑更换npm仓库,加快下载包的速度. 1.通过config命令 npm config set registry https://registry.npm ...

  3. 《转》快速导出SSRS之RDL文件

    select name,[path],cast(cast(content AS varbinary(max)) as xml) as RDLDef from dbo.[Catalog] where t ...

  4. 浅谈Http1.0/Http1.1/Http2.0/Https

    HTTP 1.0 → HTTP 1.1 长连接 HTTP 1.1默认支持长连接,减少了TCP连接次数,节约开销. HTTP 1.0所保持的TCP每次只能处理一个请求,最典型的就是pipline管线化模 ...

  5. CentOS 6.5系统安装编译安装MySQL 5.6详细过程

    点评:CentOS 6.5下通过yum安装的MySQL是5.1版的,比较老,那我们就通过源代码安装高版本的MySQL5.6.14.一:卸载旧版本使用下面的命令检查是否安装有MySQL Server r ...

  6. django 模板关闭特殊字符转化

    默认情况下,在django admin管理界面和页面中,如果输出的对象中包含HTML特殊字符,在django中默认的处理方式是将对象中的HTML特殊字符转化,例如会将 "<" ...

  7. centos7下Firewall使用详解

    安装它,只需 # yum install firewalld如果需要图形界面的话,则再安装# yum install firewall-config 一.介绍 防火墙守护 firewalld 服务引入 ...

  8. 机器学习The Learning Problem——coursera简要总结

    1.人类及动物的学习模式:观察->学习->技能 机器学习的模式:data->ML(机器学习)->skill 2.那什么是skill:技能是某种表现方法的增进   eg:stac ...

  9. java 输出helloword

    1,安装jdk;2,配置环境变量;3,新建D:/Test.java文件;4,文件内容如下:public class Test{ public static void main(String[] arg ...

  10. (转)ASP连接sql server实例解析

    本文转载自:http://blog.csdn.net/xys_777/article/details/5696276 1.首先确定自己的iis没有问题 2.其次确定自己sqlserver没有问题 然后 ...