为了账号安全,请及时绑定邮箱和手机立即绑定

Flask 应用程序超出 Python 最大递归深度

Flask 应用程序超出 Python 最大递归深度

ibeautiful 2022-11-29 14:52:40
这是错误:maximum recursion depth exceeded while calling a Python object我正在使用beautifulsoup解析从中接收到的网页 HTML,requests然后将解析后的数据存储到Product类中。该函数通过从 调用一个线程来运行ThreadPoolExecutor()。运行功能:executor = ThreadPoolExecutor()t2 = executor.submit(ScrapePageFull, PageHtml)product = t2.result()ScrapePageFull功能:def ScrapePageFull(data):soup = BeautifulSoup(data)product = Product()# Priceprice = soup.find(DIV, {ID: DATA_METRICS})[ASIN_PRICE]product.price = float(price)# ASINASIN = soup.find(DIV, {ID: DATA_METRICS})[ASIN_ASIN]product.asin = ASIN# Titletitle = soup.find(META, {NAME: TITLE})[CONTENT]product.title = title# Price Stringprice_string = soup.find(SPAN, {ID: PRICE_BLOCK}).textproduct.price_string = price_stringreturn product这是Product课程:class Product:def __init__(self):    self.title = None    self.price = None    self.price_string = None    self.asin = None    pass# Getters@propertydef title(self):    return self.title@propertydef price(self):    return self.price@propertydef asin(self):    return self.asin@propertydef price_string(self):    return self.price_string# Setters@title.setterdef title(self, title):    self.title = title@price.setterdef price(self, price):    self.price = price@asin.setterdef asin(self, asin):    self.asin = asin@price_string.setterdef price_string(self, price_string):    self.price_string = price_string感谢您的帮助,谢谢。
查看完整描述

1 回答

?
慕田峪4524236

TA贡献1875条经验 获得超5个赞

你在这里进入无限递归:


@property

def title(self):

    return self.title

返回self.title与再次调用此函数相同,因为定义一个名为的函数title会覆盖变量self.title。


这也是无限递归:


@title.setter

def title(self, title):

    self.title = title

@title.setter将重新定义赋值,比如从这个函数self.title = title中调用。self.title.setter(title)


对于和 也是一样self.price的。self.price_stringself.asin


要解决此问题,请重命名您的变量:


def __init__(...):

   self._title = None


@property

def title(self):

    return self._title


查看完整回答
反对 回复 2022-11-29
  • 1 回答
  • 0 关注
  • 288 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号