【问题标题】:typeerror 'bytes' object is not callabletypeerror 'bytes' 对象不可调用
【发布时间】:2015-02-14 11:32:51
【问题描述】:

我的代码:

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)

我收到此错误:

Traceback (most recent call last):

File "C:\Users\Prime\Documents\NetBeansProjects\Fp_API\src\fp_api.py", line 18, in <module>

    con_page = resp.content()

TypeError: 'bytes' object is not callable

【问题讨论】:

  • 似乎是在说“内容”不是函数,而实际上是“字节”类型。尝试删除括号。

标签: python byte typeerror


【解决方案1】:

基于documentationrequests.get()的返回值是requests.Response,它有一个content字段,类型为bytes,而不是content()方法。

试试这个:

con_page = resp.content

【讨论】:

  • @ManishGupta,不客气。如果它解决了您的问题,请接受答案。
猜你喜欢
  • 1970-01-01
  • 2021-03-31
  • 1970-01-01
  • 1970-01-01
  • 2018-12-25
  • 2021-04-15
  • 2011-10-01
  • 2020-11-10
  • 2017-09-09
相关资源
最近更新 更多