Python: AttributeError: 'Response' object has no attribute 'read'

23,044

You want to use res.text instead. The read() attribute doesn't exist in the Response object.

Share:
23,044
Santosh
Author by

Santosh

Updated on May 24, 2020

Comments

  • Santosh
    Santosh almost 4 years

    Here is my code: I tried to read a web page and select few html items for further processing

    from selenium import webdriver
    from bs4 import BeautifulSoup
    from urllib.request import urlopen
    from urllib.parse import urlparse
    import requests, bs4
    
    res = requests.get('http://www.iceomatic.com/Products/Ice-Machines/Cubers/')
    icesoup = bs4.BeautifulSoup(res.read())
    selectElems = icesoup.select('li')
    len(selectElems)
    type(selectElems[0])
    selectElems[0].click()
    

    And it throws the following error:

    Traceback (most recent call last):
    File "web.py.txt", line 18, in <module>
    icesoup = bs4.BeautifulSoup(res.read())
    AttributeError: 'Response' object has no attribute 'read'
    Exception ignored in: <bound method Service.__del__ of 
    <selenium.webdriver.chrome.service.Service object at 0x0000028FA783A0B8>>
    Traceback (most recent call last):
    File "C:\Users\Santosh\Anaconda3\lib\site-
    packages\selenium\webdriver\common\service.py", line 163, in __del__
    File "C:\Users\Santosh\Anaconda3\lib\site-
    packages\selenium\webdriver\common\service.py", line 139, in stop
    File "C:\Users\Santosh\Anaconda3\lib\site-
    packages\selenium\webdriver\common\service.py", line 110, in 
    send_remote_shutdown_command
    ImportError: sys.meta_path is None, Python is likely shutting down
    

    Please suggest a solution.

    Thanks