sourcetip

'NoneType' 오류로 인해 Google트랜스가 작동을 중지함 개체에 'group' 특성이 없음

fileupload 2023. 6. 27. 22:30
반응형

'NoneType' 오류로 인해 Google트랜스가 작동을 중지함 개체에 'group' 특성이 없음

노력하고 있었습니다.googletrans그리고 그것은 꽤 잘 작동했습니다.오늘 아침부터 저는 아래의 오류를 받기 시작했습니다.스택 오버플로 및 다른 사이트의 여러 게시물을 살펴보니 아마도 IP가 한동안 서비스 사용이 금지된 것 같습니다. 서비스 , IP는 같은 문제에 해 있습니다? 사용하려고 . 또한 사용하려고 했습니다.googletrans다른 노트북에서, 여전히 같은 문제.아이즈googletrans패키지가 깨졌거나 구글이 그들의 끝에서 무엇을 했습니까?

>>> from googletrans import Translator
>>> translator = Translator()
>>> translator.translate('안녕하세요.')

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    translator.translate('안녕하세요.')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/client.py", line 172, in translate
    data = self._translate(text, dest, src)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/client.py", line 75, in _translate
    token = self.token_acquirer.do(text)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/gtoken.py", line 180, in do
    self._update()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googletrans/gtoken.py", line 59, in _update
    code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'

업데이트 06.12.20: 수정된 구글 트랜스의 새로운 '공식' 알파 버전이 출시되었습니다.

알파 버전을 다음과 같이 설치합니다.

pip install googletrans==3.1.0a0

번역 예제:

translator = Translator()
translation = translator.translate("Der Himmel ist blau und ich mag Bananen", dest='en')
print(translation.text)
#output: 'The sky is blue and I like bananas'

작동하지 않는 경우 다음과 같이 서비스 URL을 지정합니다.

from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
translator.translate("Der Himmel ist blau und ich mag Bananen", dest='en')

자세한 내용 및 업데이트는 https://github.com/ssut/py-googletrans/pull/237 에서 확인할 수 있습니다.

업데이트 10.12.20: 다른 수정 사항이 릴리스되었습니다.

@DesiKeki와 @AhmedBreem이 지적했듯이, 여러 사람들에게 효과가 있는 것으로 보이는 또 다른 해결책이 있습니다.

pip install googletrans==4.0.0-rc1

여기서 Github 토론: https://github.com/ssut/py-googletrans/issues/234#issuecomment-742460612

위의 수정 사항이 귀하에게 적용되지 않는 경우

만약 위의 것들이 당신에게 효과가 없다면,google_trans_new어떤 사람들에게는 효과가 있는 좋은 대안인 것 같습니다.위의 해결책이 일부에게는 효과가 있고 다른 사람에게는 효과가 없는 이유는 분명하지 않습니다.설치 및 사용에 대한 자세한 내용은 여기를 참조하십시오. https://github.com/lushan88a/google_trans_new

#pip install google_trans_new

from google_trans_new import google_translator  
translator = google_translator()  
translate_text = translator.translate('สวัสดีจีน',lang_tgt='en')  
print(translate_text)
#output: Hello china

2020년 1월 12일 업데이트:최근 Google 번역 API의 일부 변경으로 인해 이 문제가 다시 발생했습니다.

이번 Github 이슈에서 해결책이 (다시) 논의되고 있습니다.아직 확실한 해결책은 없지만, https://github.com/ssut/py-googletrans/pull/237 에서 Pull Request를 통해 문제가 해결되는 것 같습니다.

승인을 기다리는 동안 다음과 같이 설치할 수 있습니다.

$ pip uninstall googletrans
$ git clone https://github.com/alainrouillon/py-googletrans.git
$ cd ./py-googletrans
$ git checkout origin/feature/enhance-use-of-direct-api
$ python setup.py install

원본 답변:

분명히 그것은 구글 측에서 최근에 널리 퍼진 문제입니다.다양한 Github 토론을 인용하면, 구글이 직접 원시 토큰을 보낼 때 발생합니다.

지금 논의 중이고 이미 풀 요청이 있어서 며칠 안에 해결되어야 합니다.

자세한 내용은 다음을 참조하십시오.

https://github.com/ssut/py-googletrans/issues/48 <-- Github repo에서 보고된 것과 똑같은 문제 https://github.com/pndurette/gTTS/issues/60 <-- 텍스트 간 라이브러리에서 동일한 문제인 처럼 보이는 문제 https://github.com/ssut/py-googletrans/pull/78 <-- 문제 해결을 위한 요청 꺼내기

이 패치를 적용하려면(풀 요청이 수락될 때까지 기다리지 않고) 분기된 repo https://github.com/BoseCorp/py-googletrans.git 에서 라이브러리를 설치하면 됩니다(공식 라이브러리 먼저 다운로드).

$ pip uninstall googletrans
$ git clone https://github.com/BoseCorp/py-googletrans.git
$ cd ./py-googletrans
$ python setup.py install

곳에나 할 수 .virtualenv.

Google_trans_new를 사용해 보십시오.그것은 저를 위해 문제를 해결했습니다. https://github.com/lushan88a/google_trans_new

pip install google_trans_new

from google_trans_new import google_translator  
  
translator = google_translator()  
translate_text = translator.translate('Hola mundo!', lang_src='es', lang_tgt='en')  
print(translate_text)
-> Hello world!

불행하게도, 나는 둘 다 얻을 수 없었습니다.googletrans도 아니다google_trans_new많은 제안된 수정 사항에도 불구하고 작동합니다.

내 해결책은 다음으로 전환하는 것이었습니다.deep_translator패키지:

pip install -U deep-translator

그런 다음 다음과 같이 사용할 수 있습니다.

>>> from deep_translator import GoogleTranslator
>>> GoogleTranslator(source='auto', target='de').translate("keep it up, you are awesome") 
'weiter so, du bist toll'

자세한 내용은 설명서를 참조하십시오.

2021년 9월 기준 업데이트된 답변

pip uninstall googletrans==4.0.0-rc1

pip install googletrans==3.1.0a0

3.1.0a0 버전은 대량 번역에서도 작동합니다!

업데이트 10.12.20: 새로운 알파 버전 출시(안정적 출시 후보): 4.0.0-rc1

다음과 같이 설치할 수 있습니다.

pip install googletrans==4.0.0-rc1

용도:

translation = translator.translate('이 문장은 한글로 쓰여졌습니다.', dest='en')
print(translation.text)
>>This sentence is written in Korean.
detected_lang = translator.detect('mein english me hindi likh raha hoon')
print(detected_lang)
>>Detected(lang=hi, confidence=None)
detected_lang = translator.detect('이 문장은 한글로 쓰여졌습니다.')
print(detected_lang)
>>Detected(lang=ko, confidence=None)

이 대답을 들을 때까지 다음과 같은 방법으로 문제를 해결할 수 있습니다.

설치된 의 버전 제거

pip uninstall googletrans

다음 버전 설치

pip install googletrans==4.0.0rc1

저는 이것이 저에게 효과가 있었던 것처럼 당신에게도 효과가 있기를 바랍니다.

지금 바로 사용할 수 있습니다.

from googletrans import Translator
translator = Translator()
ar = translator.translate('مرحبا').text
print(ar)

4.0.0rc1의 이전 .httpx.py fix client.py 을 수정해야 .httpcore.SyncHTTPTransporthttpcore.AsyncHTTPProxy.

Darkblader24가 https://github.com/ssut/py-googletrans/pull/78 에서 언급했듯이 이 문제에 대한 비공식적인 해결책이 있습니다.

다음과 같이 gtoken.py 을 업데이트합니다.

    RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);',
                        re.DOTALL)
    RE_RAWTKK = re.compile(r'TKK=\'([^\']*)\';',re.DOTALL)

    def __init__(self, tkk='0', session=None, host='translate.google.com'):
        self.session = session or requests.Session()
        self.tkk = tkk
        self.host = host if 'http' in host else 'https://' + host

    def _update(self):
        """update tkk
        """
        # we don't need to update the base TKK value when it is still valid
        now = math.floor(int(time.time() * 1000) / 3600000.0)
        if self.tkk and int(self.tkk.split('.')[0]) == now:
            return

        r = self.session.get(self.host)

        rawtkk = self.RE_RAWTKK.search(r.text)
        if rawtkk:
            self.tkk = rawtkk.group(1)
            return

이것은 저에게 효과가 있었습니다.

pip install googletrans==4.0.0-rc1

원본 답변은 https://github.com/ssut/py-googletrans/issues/234#issuecomment-742460612 에서 확인할 수 있습니다.

Fixed는 여기 있습니다. https://pypi.org/project/py-translator/

pip3 설치 py_creator==1.8.9

from py_translator import Translator
s = Translator().translate(text='Hello my friend', dest='es').text
print(s)

아웃:홀라미아미고

pip uninstall googletrans googletrans-temp
pip install googletrans-temp

2019.2.24 기준 Win10 및 Ubuntu 16(Python 3.6)에서 근무했습니다. -- https://github.com/ssut/py-googletrans/issues/94 의 답변 중 하나를 참조하십시오.낡은 해결책pip install git+https://github.com/BoseCorp/py-googletrans.git --upgrade여기서는 더 이상 작동하지 않습니다.

최신 파이썬에서는 Google Trans가 지원되지 않으므로 제거해야 합니다.

새 Google Trans를 장착하십시오(ip install Google Trans==3.1.0a0).

이것이 제가 제 문제를 해결한 방법입니다.

pip3 uninstall googletrans
pip3 install googletrans==3.1.0a0

먼저 이전 버전을 제거하고 3.1.0 버전을 설치해야 합니다.

여기서 번역기 패키지 사용

  1. 작동합니다(;
  2. Google보다 더 많은 기능 지원

설치:

pip install translators --upgrade

용도:


    >>> import translators as ts
    Using Israel server backend.
    >>> ts.google('שלום' , to_language = 'es')
    'Hola'
    

토큰을 다음과 같이 변경한 것이 저에게 도움이 되었습니다.

RE_TKK = re.compile(r'tkk:\'(.+?)\'')      

def __init__(self, tkk='0', session=None, host='translate.google.com'):
    self.session = session or requests.Session()
    self.tkk = tkk
    self.host = host if 'http' in host else 'https://' + host

def _update(self):
    """update tkk
    """
    # we don't need to update the base TKK value when it is still valid
    r = self.session.get(self.host)        

    self.tkk = self.RE_TKK.findall(r.text)[0]

    now = math.floor(int(time.time() * 1000) / 3600000.0)
    if self.tkk and int(self.tkk.split('.')[0]) == now:
        return

    # this will be the same as python code after stripping out a reserved word 'var'
    code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
    # unescape special ascii characters such like a \x3d(=)

저는 여기 티켓에서 이 스니펫을 얻었습니다.

이것은 Kerem이 앞서 제안한 다른 변화와는 약간 다릅니다.

저처럼 초보자가 아닌 다른 사람들은 Anaconda를 사용하는 Windows 시스템의 AppData\Local\Continuum\anaconda3\site-packages\googletrans에서 gtoken.py 를 찾을 수 있습니다.AppData를 찾으려면 파일 탐색기의 주소 표시줄에 들어가 '%AppData%'를 입력하고 Enter를 누릅니다.

시도/제외 차단으로 문제가 해결되었습니다.

try:
    langs = translator.detect(update.message.text)
    if langs.lang == 'en':
        foo(translator.translate(update.message.text,dest='zh-cn').text)
    else:
        bar(translator.translate(update.message.text,dest='en').text)
except Exception as e:
    print(e)

Google Colab 또는 Jupyter 노트북을 사용하는 경우 다음을 실행합니다.

!pip uninstall googletrans

런타임을 다시 시작하고 다음을 실행합니다.

!pip install googletrans==4.0.0rc1

시도 - pip 설치 Google트랜스==3.1.0a0

언급URL : https://stackoverflow.com/questions/52455774/googletrans-stopped-working-with-error-nonetype-object-has-no-attribute-group

반응형