googletrans python AttributeError:“ NoneType”对象没有属性“ group”

时间:2020-11-04 11:37:14

标签: python discord discord.py google-translate translators

所以,我已经准备了像这样的代码:

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))

它是不和谐的bot,过去一切正常,但是最近它开始崩溃的频率越来越高,这是一个错误日志:

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'

我已经阅读了有关它的内容,并尝试了here的一些解决方案,但是似乎没有什么对我有用,也许与这个问题不同吗?我只是不知道该怎么办,有人可以帮忙吗?

编辑:添加了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'

0 个答案:

没有答案
相关问题