[2022-03-11 05:07:57,224] ERROR {cps:1457} Exception on /metadata/search [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/local/lib/python3.8/dist-packages/flask_login/utils.py", line 272, in decorated_view
return func(*args, **kwargs)
File "/app/calibre-web/cps/search_metadata.py", line 133, in metadata_search
data.extend([asdict(x) for x in future.result()])
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 437, in result
return self.__get_result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
raise self._exception
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
TypeError: search() takes from 2 to 3 positional arguments but 4 were given
添加传入参数后:
[2022-03-11 05:28:23,011] ERROR {cps:1457} Exception on /metadata/search [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/local/lib/python3.8/dist-packages/flask_login/utils.py", line 272, in decorated_view
return func(*args, **kwargs)
File "/app/calibre-web/cps/search_metadata.py", line 133, in metadata_search
data.extend([asdict(x) for x in future.result()])
File "/app/calibre-web/cps/search_metadata.py", line 133, in <listcomp>
data.extend([asdict(x) for x in future.result()])
File "/usr/lib/python3.8/dataclasses.py", line 1072, in asdict
raise TypeError("asdict() should be called on dataclass instances")
TypeError: asdict() should be called on dataclass instances
对DoubanBookHtmlParser进行修改后可以正常使用:
def parse_book(self, url, book_content):
book = MetaRecord(
id = "",
title = "",
authors = "",
url = "",
source=MetaSourceInfo(
id=PROVIDER_ID,
description=PROVIDER_NAME,
link="https://book.douban.com/"
)
)
html = etree.HTML(book_content)
title_element = html.xpath("//span[@property='v:itemreviewed']")
book.title = self.get_text(title_element)
share_element = html.xpath("//a[@data-url]")
if len(share_element):
url = share_element[0].attrib['data-url']
book.url = url
id_match = self.id_pattern.match(url)
if id_match:
book.id = id_match.group(1)
img_element = html.xpath("//a[@class='nbg']")
if len(img_element):
cover = img_element[0].attrib['href']
if not cover or cover.endswith('update_image'):
book.cover = ''
else:
book.cover = cover
rating_element = html.xpath("//strong[@property='v:average']")
book.rating = self.get_rating(rating_element)
elements = html.xpath("//span[@class='pl']")
book.authors = []
book.publisher = ''
for element in elements:
text = self.get_text(element)
if text.startswith("作者"):
book.authors.extend([self.get_text(author_element) for author_element in filter(self.author_filter, element.findall("..//a"))])
elif text.startswith("译者"):
book.authors.extend([self.get_text(author_element) for author_element in filter(self.author_filter, element.findall("..//a"))])
elif text.startswith("出版社"):
book.publisher = self.get_tail(element)
elif text.startswith("副标题"):
book.title = f"{book.title}:{self.get_tail(element)}"
elif text.startswith("出版年"):
book.publishedDate = self.get_tail(element)
elif text.startswith("丛书"):
book.series = self.get_text(element.getnext())
summary_element = html.xpath("//div[@id='link-report']//div[@class='intro']")
book.description = ''
if len(summary_element):
book.description = etree.tostring(summary_element[-1], encoding="utf8").decode("utf8").strip()
tag_elements = html.xpath("//a[contains(@class, 'tag')]")
if len(tag_elements):
book.tags = [self.get_text(tag_element) for tag_element in tag_elements]
return book
与issue #5 的问题相同。
主要是因为上游[4f3c39]中对
cps/search_metadata.py
和cps/services/Metadata.py
的更改。Metadata
的search
方法增加了locale
参数,并修改返回类型为List[MetaRecord]
。也就是说版本0.6.17对metadata_provider产生了breaking change,无法与前面的版本兼容了。
以下为日志:
添加传入参数后:
对DoubanBookHtmlParser进行修改后可以正常使用: