UrlLink.create()方法报错:TypeError: __init__() got an unexpected keyword argument 'thumbnailUrl'
出错代码:
await conversation.say('dong')
file_box = FileBox.from_url(
'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/'
'u=1116676390,2305043183&fm=26&gp=0.jpg',
name='ding-dong.jpg')
await conversation.say(file_box)
ur_link=UrlLink.create("https://mp.weixin.qq.com/s/BqXNpYZXDgBrEQBzj_BB_w")
await conversation.say(ur_link)
错误信息:
INFO:UrlLink:create url_link for https://mp.weixin.qq.com/s/BqXNpYZXDgBrEQBzj_BB_w
ERROR:__main__:__init__() got an unexpected keyword argument 'thumbnailUrl'
Traceback (most recent call last):
File "/root/wechaty/python-wechaty-getting-started/my_wechaty/ding-dong-bot-oop.py", line 46, in send_url_link
ur_link=UrlLink.create(url="https://mp.weixin.qq.com/s/BqXNpYZXDgBrEQBzj_BB_w")
File "/usr/local/python3.9/lib/python3.9/site-packages/wechaty/user/url_link.py", line 44, in create
payload = UrlLinkPayload(
TypeError: __init__() got an unexpected keyword argument 'thumbnailUrl'
描述: 文本信息和图片都能正常发送,url封装报错
环境:
wechaty包版本 0.6.1
python3.9
linux版本:Linux version 3.10.0-693.2.2.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Sep 12 22:26:13 UTC 2017
I think you've made a mistake. The UrlLink.create function without any issue, you should use it as below:
url = f'''https://github.com/wechaty/python-wechaty/issues/182'''
title =f'''UrlLink.create()方法报错'''
description = f'''测试图文'''
thumbnailUrl = f'''https://openai-75050.gzc.vod.tencent-cloud.com/openaiassets_29273cc951a4deff6559039c46c22d8a.jpg'''
send_url = UrlLink.create(url=url, title=title, thumbnail_url=thumbnailUrl, description=description)
await room.say(send_url)
because I use the wechaty version=0.6.1,UrlLink.create() method only apply one parameter:
@classmethod
def create(
cls: Type[UrlLink],
url: str,
) -> UrlLink:
"""
create urllink from url string
"""
log.info('create url_link for %s', url)
html = etree.HTML(requests.get(url).text)
title = html.xpath('//meta[@property="og:title"]/@content')
thumbnail_url = html.xpath('//meta[@property="og:image"]/@content')
description = html.xpath('//meta[@property="og:description"]/@content')
payload = UrlLinkPayload(
title=title[0] if len(title) else url,
url=url,
thumbnailUrl=thumbnail_url[0] if len(thumbnail_url) else "",
description=description[0] if len(description) else ""
)
return UrlLink(payload)
I think maybe my wechaty version not suitable. Can you tell me your wechaty version which use UrlLink.create() successfully? Because when I use the latest wechaty version 0.7dev15 first time,the excample ding-dong-bot.py having strange mistake. Thank you wery much.
Please make sure that the version of your wechaty is latest which is more stable than older. If ding-dong-bot.py meets strange mistake, you should try to debug and fix it. If you can't fix, you can fire an issue to describe it, so that we can help you. Please feel free to tell us all of your problems. Thx.