Chaitanya Nettem
Chaitanya Nettem

Reputation: 1239

Requests example returns an error

I am working on a project that requires web scraping. Hence I was looking at the Requests library in Python. In the quickstart page of the library the following code example is given:

>>> import requests
>>> r = requests.get('https://github.com/timeline.json')
>>> r.text
'[{"repository":{"open_issues":0,"url":"https://github.com/...

On trying out that code I found that the following error is returned when I try to print r.text:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Response' object has no attribute 'text'

What am I doing wrong?

Upvotes: 1

Views: 2869

Answers (1)

root
root

Reputation: 80336

try r.content -- it should work with an older version of requests or upgrade. To upgrade requests on python 2.7 use sudo pip-2.7 install requests --upgrade

Upvotes: 1

Related Questions