typeerror 'bytes' object is not callable

Question:

My code:

import psycopg2
import requests
from urllib.request import urlopen
import urllib.parse
uname = " **** "
pwd = " ***** "
resp = requests.get("https://api.flipkart.net/sellers/skus/SKUID/listings", auth=(uname, pwd))
con_page = resp.content()
print (con_page)

I am getting this error:

Traceback (most recent call last):

File "C:UsersPrimeDocumentsNetBeansProjectsFp_APIsrcfp_api.py", line 18, in <module>

    con_page = resp.content()

TypeError: 'bytes' object is not callable
Asked By: Manish Gupta

||

Answers:

Based on the documentation, the return value of requests.get() is a requests.Response, which has a content field with the type bytes, rather than a content() method.

Try this instead:

con_page = resp.content
Answered By: merlin2011

do this:
con_page = resp.content.decode()

Answered By: Rohan Kumar Reddy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.