ATTRIBUTEERROR: 'BYTES' OBJECT HAS NO ATTRIBUTE 'getheader'

so i am trying to run the initial spider of a webcrawler and i keep getting AttributeError: 'bytes' object has no attribute 'getheader' error message. As a method in the spider class, i defined a function to parse and extract html(in strings) using getheader() to access header info but i still keep getting the error message. What attribute can i use in place of getheader() or get() to make this work? Please help. here is the code:

@staticmethod
def gather_links(page_url):
    html_string=''
    response=urllib.request.urlopen(page_url, context=ctx).read()
    if 'text/html' in response.getheader('Content Type'):
        html_bytes= response.read()
        html_string=html_bytes.decode()
    finder= LinkFinder(spider.base_url, page_url)
    finder.feed(html_string)
    #except:
    #    print('Error: Can not crawl page')
    #    return set()
728x90

0 Answers ATTRIBUTEERROR: 'BYTES' OBJECT HAS NO ATTRIBUTE 'getheader'