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 ...
随机推荐
- How to get the full error stack trace of SharePoint
博客地址 http://blog.csdn.net/foxdave SharePoint开发,怎么得到真实的详细错误信息. 大家在开发遇到页面报错需要提问的时候,先将详细错误信息获取到再提问,谢谢. ...
- L181 The microscopic structure of a cat’s tongue helps keep its fur clean
T.S. eliot's mystery cat, Macavity, besides being a criminal mastermind able to evade the combined r ...
- Git 之 git原理简介
这里只是很简单.超简单的介绍下git,为的是方便记忆: 本地仓库分为三个部分:工作区.暂存区.仓库区,其中暂存区和仓库区属于版本区. 对于文件的操作,需要从工作区----> 暂存区 ----&g ...
- Nginx 防盗链设置
何谓'盗链' 此内容不在自己服务器上,而通过技术手段,绕过别人放广告有利益的最终页,直接在自己的有广告有利益的页面上向最终用户提供此内容. 常常是一些名不见经传的小网站来盗取一些有实力的大网站的地址( ...
- 重新学习之spring第二个程序,配置AOP面向切面编程
第一步:在配置好的ioc容器的基础上,导入面向切面编程所需要的jar包 (本案例用的是spring3.2.4,由于spring3.2.4的官网jar包中不再有依赖包,所以依赖包都是从网上找的) 第二步 ...
- test20181024 zi
题意 分析 这种题一般是推公式,发现必须求得的量,然后定义函数记忆化. 然后那些函数里面又是递归处理,合并. 代码 为了不爆空间,用map存记忆化内容. #include<bits/stdc++ ...
- yarn workspaces基本试用
初始化项目 yarn init -y 添加workspaces 支持 修改package.json { "name": "second", "vers ...
- ORA-01033: ORACLE initialization or shutdown in progress --手动删除表空间 DBF 后无法登陆问题
进入CMD,执行set ORACLE_SID=fbms,确保连接到正确的SID: 2.执行sqlplus "/as sysdba" SQL>shutdown immediat ...
- c# 子线程如何通知主线程,个人总结
我要实现的功能如下:程序中有2个线程,主线程和子线程,主线程中有一个变量:X主线程运行中激活子线程,子线程会做出计算改变 X 的值,主线程继续做其它的事,直到 X 的值发生改变时,才会响应,并在tex ...
- windows7安装django并创建第一个应用
1.安装django 1.1.下载Django包 https://www.djangoproject.com/download/https://www.djangoproject.com/m/rele ...