AttributeError: 'Response' 对象没有属性 'text' [英] AttributeError: 'Response' object has no attribute 'text'

查看:115
本文介绍了AttributeError: 'Response' 对象没有属性 'text'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

page = requests.get(url)
tree = html.fromstring(page.text)

在第 2 行我得到:

AttributeError: 'Response' object has no attribute 'text'

我导入了请求并安装了请求.如何调试此错误?谁能告诉命令安装最新的请求模块?

I have imported requests and installed requests. How do I debug this error? can anyone tell command to install lastest requests module?

推荐答案

您正在使用 requests 的旧版本,很可能是因为它是随 Ubuntu Precise Pengolin (12.04LTS).

You are using an ancient version of requests, most likely because it came installed with Ubuntu Precise Pengolin (12.04LTS).

您要么必须参考版本特定文档,要么使用更新的版本.requests 自 0.x 版本以来发生了巨大的变化.

You'll either have to refer to the version specific documentation or use a more recent version. requests has changed drastically since the 0.x version days.

对于你的旧版本,如果你设置了 response.encodingresponse.content 将包含一个解码后的 Unicode 值.

For your old version, if you set response.encoding, response.content will contain a decoded Unicode value.

这篇关于AttributeError: 'Response' 对象没有属性 'text'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆