💡 尝试通过循环修复一言报错

This commit is contained in:
Xtao_dada 2020-05-16 23:10:12 +08:00 committed by GitHub
parent e3e92ab69d
commit 06c726bc30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -157,7 +157,17 @@ async def feet2meter(context):
description="发送一句一言")
async def hitokoto(context):
""" Get hitokoto.cn """
hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8").content.decode("utf-8"))
hitokoto_while = 1
try:
hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8").content.decode("utf-8"))
except (ValueError):
while hitokoto_while < 10:
hitokoto_while += 1
try:
hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8").content.decode("utf-8"))
break
except:
continue
if hitokoto_json['type'] == 'a':
hitokoto_type = '动画'
elif hitokoto_json['type'] == 'b':
@ -196,4 +206,4 @@ async def source(context):
description="显示原始 PagerMaid 项目主页的URL。")
async def site(context):
""" Outputs the site URL. """
await context.edit("https://katonkeyboard.moe/pagermaid.html")
await context.edit("https://katonkeyboard.moe/pagermaid.html")