Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"'Nonetype' object is not subscriptable" error on bulk translate #9

Open
kyle-sama opened this issue Jan 14, 2021 · 5 comments
Open

Comments

@kyle-sama
Copy link

Tried to use bulk translate on a pdf file:

from pygoogletranslation import Translator

translator = Translator()

translation = translator.translate('日本語')
print(translation)
>>Translated(src=ja, dest=en, text=Japanese, pronunciation=, original_text=日本語 ,extra_data="{}...")
bulk = translator.bulktranslate('annotation_ID07.pdf', src='ja', dest='en')

got this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-6655f63a5be2> in <module>
----> 1 bulk = translator.bulktranslate('annotation_ID07.pdf', src='ja', dest='en')

~\AppData\Roaming\Python\Python37\site-packages\pygoogletranslation\translate.py in bulktranslate(self, file, src, dest)
    257         text = text.replace('"', '')
    258         text = text.replace("'", "")
--> 259         data = self._translate(text, src=src, dest=dest)
    260         return self.extract_translation(data, text)
    261 

~\AppData\Roaming\Python\Python37\site-packages\pygoogletranslation\translate.py in _translate(self, text, src, dest)
    185                     raise Exception('Unexpected status code {} from {}'.format(response.status_code, self.transurl))
    186                     return False
--> 187             translated_list.append(utils.format_translation(trans_list))
    188         return translated_list
    189 

~\AppData\Roaming\Python\Python37\site-packages\pygoogletranslation\utils.py in format_translation(translated)
     90     pron = ''
     91     for _translated in translated:
---> 92         text += _translated[0][2][1][0][0][5][0][0]
     93         try:
     94             pron += unidecode.unidecode(_translated[0][2][1][0][0][1])

TypeError: 'NoneType' object is not subscriptable
@Saravananslb
Copy link
Owner

Hi kyle-sama,

Please share the pdf to saravananslb2015@gmail.com

I will help you on this issue bcz I have tested with some pdf files that is working file.

So I need a PFD file that you are trying to translate.

Thanks,
Saravananslb

@kyle-sama
Copy link
Author

I'm sorry, it's sensitive data that I cannot share, but I'll see if I can try on something else

@kyle-sama
Copy link
Author

yeah other files don't throw the errors, but give various results...

@Saravananslb
Copy link
Owner

Saravananslb commented Jan 14, 2021

Try this version pip install pygoogletranslation==2.0.4.

I hope this will fix ur error.

Please let me know ur feedback.

@bjquinniii
Copy link

Random thought about the pdf file that wasn't working... what kind of pdf is it? What I mean by that is that if it's really a scanned pdf, then you're unlikely to have much luck with it without some fairly sophisticated ocr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants