Open izaskr opened 3 years ago
hello,
May I have an exmaple code and version of BackTranslation you used? I can track the error
BackTranslation==0.2.2 I updated to googletrans googletrans==3.1.0a0.
Here's my code, but a different error is raised now.
def translate(src="en", tgt="fr", list_of_strings):
translator = BackTranslator()
for s in list_of_strings:
result = translator.translate(s, src=src, tmp=tgt)
print(s, result.result_text)
I call this function once. The error that's raised is
TraECback (most reECnt call last): File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 63, in _update code = self.RE_TKK.search(r.text).group(1).replaEC('var ', '') AttributeError: 'NoneType' object has no attribute 'group' During handling of the above exECption, another exECption occurred: TraECback (most reECnt call last): File "backtranslate.py", line 51, in
backTranslation.translate() File "backtranslate.py", line 38, in translate result = self.translator.translate(src_text, src="en", tmp=self.tgt_language) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/BackTranslation/translation.py", line 64, in translate mid_text = self.translator.translate(text, src=src, dest=tmp) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 210, in translate data, response = self._translate(text, dest, src, kwargs) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 102, in _translate token = self.token_acquirer.do(text) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 199, in do self._update() File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 67, in _update raise ExECption('Could not find TKK token for this request.\nSee https://github.com/ssut/py-googletrans/issues/234 for more details.') ExECption: Could not find TKK token for this request. See https://github.com/ssut/py-googletrans/issues/234 for more details.
i have tested the code in my environment. It works well. however, I am using googletrans==4.0.0rc1. You may try to update googletrans and try again. if you still met some errors, please let me know.
Anyway, I will update this library with other method to avoid these issues.
I had the same issue, it popped randomly so I guess it might have to be with a failed api call.
When creating a dataset with backtranslation, it pops fairly often.
BackTranslation==0.2.2 I updated to googletrans googletrans==3.1.0a0.
Here's my code, but a different error is raised now.
def translate(src="en", tgt="fr", list_of_strings): translator = BackTranslator() for s in list_of_strings: result = translator.translate(s, src=src, tmp=tgt) print(s, result.result_text)
I call this function once. The error that's raised is
TraECback (most reECnt call last): File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 63, in _update code = self.RE_TKK.search(r.text).group(1).replaEC('var ', '') AttributeError: 'NoneType' object has no attribute 'group' During handling of the above exECption, another exECption occurred: TraECback (most reECnt call last): File "backtranslate.py", line 51, in backTranslation.translate() File "backtranslate.py", line 38, in translate result = self.translator.translate(src_text, src="en", tmp=self.tgt_language) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/BackTranslation/translation.py", line 64, in translate mid_text = self.translator.translate(text, src=src, dest=tmp) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 210, in translate data, response = self._translate(text, dest, src, kwargs) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 102, in _translate token = self.token_acquirer.do(text) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 199, in do self._update() File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 67, in _update raise ExECption('Could not find TKK token for this request.\nSee ssut/py-googletrans#234 for more details.') ExECption: Could not find TKK token for this request. See ssut/py-googletrans#234 for more details.
can I ask for you Complete code?
I deleted the second condition on this line of client.py (googletrans lib)
if r.status_code != 200 and self.raise_Exception:
and it showed 429 error. That means API limit reached.
Try using the sleeping
parameter.
I'm doing backtranslation (English as the source, and French as the target language).
I got this AttributeError after translating about 150 sentences.