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

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="发送一句一言") description="发送一句一言")
async def hitokoto(context): async def hitokoto(context):
""" Get hitokoto.cn """ """ 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': if hitokoto_json['type'] == 'a':
hitokoto_type = '动画' hitokoto_type = '动画'
elif hitokoto_json['type'] == 'b': elif hitokoto_json['type'] == 'b':