所以,我准备了这样的代码:
async def cv_local(ctx, country=""):
translator = Translator()
try:
country = translator.translate(country, dest='en').text
now = datetime.datetime.now()
# startTime = time.time()
if country == "":
country = "world"
print("At " + str(now.hour) + ":" + str(now.minute) + " user " + str(ctx.message.author.name) + "(Id: " + str(
ctx.message.author.id) + ")" +
" didn't mention any country, sent data for world")
else:
print("At " + str(now.hour) + ":" + str(now.minute) + " user " + str(ctx.message.author.name) + "(Id: " + str(
ctx.message.author.id) + ")" + " searched for: " +
str(Library.exceptionCheck(country)[1]))
if str(country).lower() == "world" or str(country).lower() == "kw" or str(country).lower() == "za":
url = 'https://www.worldometers.info/coronavirus/'
code = Library.HttpsRead(url, "świat", config[str(ctx.message.guild.id)]['lang'])
else:
temp1 = Library.exceptionCheck(country)[0]
url = 'https://www.worldometers.info/coronavirus/country/' + temp1
code = Library.HttpsRead(url, country, config[str(ctx.message.guild.id)]['lang'])
message = await ctx.send(embed=code)
await message.add_reaction("")
# print("execution took %s seconds \n" % (time.time() - startTime))
except UnboundLocalError:
await ctx.send("That's strange... It seems like you wanted data for country that doesn't exist in my database\nImportant message: if you would like to look for countries named with multiple words insert \"-\" instead of "
"spaces or use shortcuts f.e. \"uk\" instead of \"United Kingdom\" or \"south-africa\" instead of \"South Africa\"\n\n If error will be repeating report it to <@!287258679609393152>")
print("Error occurred, user missed name of country")
# print("execution took %s seconds \n" % (time.time() - startTime))
except:
await ctx.send("That's strange... Translator occurred some kind of error\nJust try again and everything should be just fine\n\n If error will be repeating report it to <@!287258679609393152>")
print("Error occurred, informed user")
# print("execution took %s seconds \n" % (time.time() - startTime))
这是不和谐的机器人,过去一切都很好,但最近它开始崩溃越来越频繁,这是一个错误日志:
Traceback (most recent call last):
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/grzes/PycharmProjects/CoronaBot/bot.py", line 222, in cv_local
country = translator.translate(country, dest='en').text
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\client.py", line 172, in translate
data = self._translate(text, dest, src)
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\client.py", line 75, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\gtoken.py", line 186, in do
self._update()
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\gtoken.py", line 65, in _update
code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
我已经阅读了一些关于它的内容并从这里尝试了一些解决方案,但似乎没有什么对我有用,也许它与这个问题不同?我只是不知道还能做什么,有人可以帮忙吗?
编辑:添加os.environ["HTTPX_LOG_LEVEL"] = "DEBUG"
并且输出是这样的:
Traceback (most recent call last):
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/grzes/PycharmProjects/CoronaBot/bot.py", line 242, in cv_local
code = Library.HttpsRead(url, country, config[str(ctx.message.guild.id)]['lang'])
File "C:\Users\grzes\PycharmProjects\CoronaBot\Library.py", line 221, in HttpsRead
embed = discord.Embed(title=translator.translate("Dane o chorobie", dest=currLang).text, description="[Support bot](https://kickstarter.com), [vote](https://top.gg), [support me](https://patreon.com)", color=0xf00000)
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\client.py", line 172, in translate
data = self._translate(text, dest, src)
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\client.py", line 75, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\gtoken.py", line 186, in do
self._update()
File "C:\Users\grzes\PycharmProjects\CoronaBot\venv\lib\site-packages\googletrans-2.3.0-py3.8.egg\googletrans\gtoken.py", line 65, in _update
code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'