Python Forum
module requests, .text extension
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
module requests, .text extension
#1
import requests
res = requests.get('https://automatetheboringstuff.com/files/rj.txt')
print(type(res))
print(res.status_code == requests.codes.ok)
print(len(res.text))
print(res.text[:250])

res = requests.get('http://inventwithpython.com/page_that_does_not_exist')
res.raise_for_status()

res = requests.get('http://inventwithpython.com/page_that_does_not_exist')
try:
    res.raise_for_status()
except Exception as exc:
	print(f'There was a problem {exc}')
In lines 5 and 6 .text is used. Why does it have to be used? Why the content of Response type res can't be printed? And if an extension must be added why not .txt?
Reply
#2
The res is an object returned from requests.get().
You use .text to get the "text" content of the object.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ModuleNotFoundError: No module named 'requests' Serg 18 2,491 Oct-29-2023, 11:33 PM
Last Post: Serg
  Python C Extension Module loading issue on Cygwin mesibo 0 642 Sep-22-2023, 05:41 AM
Last Post: mesibo
  C Extension module lamer 1 756 Jan-12-2023, 06:01 PM
Last Post: deanhystad
  Use module docx to get text from a file with a table Pedroski55 8 6,069 Aug-30-2022, 10:52 PM
Last Post: Pedroski55
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,507 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  Help with requests module 0xB9 3 2,793 Mar-14-2021, 06:49 AM
Last Post: buran
  'urllib3' Module not found when import 'requests' spanz 5 10,176 Jan-06-2021, 05:57 PM
Last Post: snippsat
  ModuleNotFoundError: No module named 'requests' Martin 2 2,415 Oct-04-2020, 03:35 PM
Last Post: Martin
  Python requests module doesn not return status_code palo173 5 3,414 May-21-2019, 09:22 AM
Last Post: buran
  No module named 'requests.packages' runnerpaul 1 9,303 Aug-18-2017, 08:49 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020