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

googletrans 4.0.0-rc1 fails with TypeError: 'NoneType' object is not iterable on client.py:222 #260

Closed
1 of 2 tasks
MaxBrain opened this issue Dec 12, 2020 · 30 comments
Closed
1 of 2 tasks

Comments

@MaxBrain
Copy link

Googletrans version:

  • 4.0.0rc1

I'm submitting a ...

  • bug report
  • feature request

Current behavior:

python3
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from googletrans import Translator
>>> translator = Translator()
>>> print(translator.translate("Author", src="en", dest="de").text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Users\Max\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googletrans\client.py", line 222, in translate
    translated_parts = list(map(lambda part: TranslatedPart(part[0], part[1] if len(part) >= 2 else []), parsed[1][0][0][5]))
TypeError: 'NoneType' object is not iterable

Expected behavior:

I expect the "Author" word in deuch

Steps to reproduce:

  • Install googletrans 4.0.0-rc1
  • Call python and make steps from "Current behavior"
@ssut
Copy link
Owner

ssut commented Dec 12, 2020

Screen Shot 2020-12-13 at 5 25 21 AM

This probably is because of the gender-specific translate results. I will investigate and fix it soon.

@noaho
Copy link

noaho commented Dec 14, 2020

I'm getting a similar issue, it seems whenever Google gives two results it fails.

[['wrb.fr', 'MkEWBc', '[[null,null,null,[[[0,[[[null,3]\n]\n,[true]\n]\n]\n,[2,[[[null,4]\n,[4,24]\n]\n,[false,true]\n]\n]\n]\n,24]\n]\n,[[[null,"\nPhraxāthity̒ kảlạng ca tkdin",null,null,null,[[null,[""]\n]\n,["\n"]\n,["พระอาทิตย์กำลังจะตกดิน",["พระอาทิตย์กำลังจะตกดิน","ดวงอาทิตย์เป็นเรื่องเกี่ยวกับชุด"]\n]\n]\n]\n]\n,"th",1,"en"]\n]\n', None, None, None, 'generic'], ['di', 63], ['af.httprm', 63, '-9129644094679872904', 37]]
sequence item 0: expected str instance, NoneType found

@ssut
Copy link
Owner

ssut commented Dec 14, 2020

@noaho Thanks for giving me the raw response. I'll fix it within a few days.

@noaho
Copy link

noaho commented Dec 15, 2020

Thank you for the great project 😊

@JosMan94
Copy link

Hello! I have the same problem too.
@ssut thank you very much for continuing with the project :D
Regards.

@ahmedbr
Copy link

ahmedbr commented Dec 18, 2020

Hi! any solution for this problem?

@ssut
Copy link
Owner

ssut commented Dec 18, 2020

@ahmedbr I'm still working on it. Give me a little time please.

@ahmedbr
Copy link

ahmedbr commented Dec 18, 2020

@ahmedbr I'm still working on it. Give me a little time please.

Thank you so much for your efforts bro, I've just faced the problem and wanted to ask whether it's been solved. Thanks again. 😄

@vbastianpc
Copy link

I think I have the solution. Replace this line 222 of googletrans/client.py with this

try:
    translated_parts = list(map(lambda part: TranslatedPart(part[0], part[1] if len(part) >= 2 else []), parsed[1][0][0][5]))
except TypeError: # because of the gender-specific translate results
    translated_parts = [ TranslatedPart(parsed[1][0][1][0], [parsed[1][0][0][0], parsed[1][0][1][0]]) ]

Gender-specific translations now work.

>>> translator.translate("Author", src="en", dest="de").text
Autor

(This is my first comment on github, I don't know how to put this code snippet in your pull request)

@ahmedbr
Copy link

ahmedbr commented Dec 30, 2020

I think I have the solution. Replace this line 222 of googletrans/client.py with this

try:
    translated_parts = list(map(lambda part: TranslatedPart(part[0], part[1] if len(part) >= 2 else []), parsed[1][0][0][5]))
except TypeError: # because of the gender-specific translate results
    translated_parts = [ TranslatedPart(parsed[1][0][1][0], [parsed[1][0][0][0], parsed[1][0][1][0]]) ]

Gender-specific translations now work.

>>> translator.translate("Author", src="en", dest="de").text
Autor

(This is my first comment on github, I don't know how to put this code snippet in your pull request)

Thanks for your reply, but this doesn't work for me

@Saravananslb
Copy link

Use this for google translation and it is working fine
https://pypi.org/project/pygoogletranslation

Thank me later

@mr2rm
Copy link

mr2rm commented Mar 8, 2021

Hi, Still any solution to this issue?
Can I work on this?

@terryyz
Copy link
Collaborator

terryyz commented Mar 10, 2021

@mr2rm You are more than welcome to work on this :)

@kidburglar
Copy link

kidburglar commented Apr 24, 2021

@ssut @mr2rm Is there a reason it's not fixed yet? I ask because I tested the change of vbastianpc and it fixed the issue in my case.

@ahmedbr do you still have a way to reproduce your issue?

@mr2rm
Copy link

mr2rm commented May 11, 2021

@kidburglar
That's because I couldn't reproduce it. It seems gender-specific translation won't return in response anymore.

@ssikyou
Copy link

ssikyou commented May 13, 2021

Same error here, it seems the issue still exsits.

@kidburglar
Copy link

@mr2rm

I will try to find few case where I can reproduct the issue. I noted that it was because the gender like you said but also if you got an URL the answer from google is not the same.

@stale
Copy link

stale bot commented Jul 16, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 16, 2021
@stale stale bot closed this as completed Jul 23, 2021
@Luke8023
Copy link

Luke8023 commented Oct 6, 2021

incorrect from en to fr gives this error

@MaxBrain
Copy link
Author

MaxBrain commented Oct 6, 2021

Actual code to reproduce

python3
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from googletrans import Translator
>>> translator = Translator()
>>> print(translator.translate("GREAT", src="en", dest="es").text)

The code from the first post still crashes

print(translator.translate("Author", src="en", dest="de").text)

@dandiep
Copy link

dandiep commented Nov 27, 2021

Still an issue. Any gendered word causes this. Another example:

translator.translate("white", src="en", dest="es")

@lesleypotters
Copy link

I still have this problem when running the code like this:
df['text_en'] = df['text'].apply(lambda x: translator.translate(x, src=es, dest='en').text )

However, when I take out the src=es part, it does run - but it gets a timeout after 1,5h.

@gonzalo-cordova-pou
Copy link

gonzalo-cordova-pou commented May 25, 2022

translator.translate("modern" , src="en", dest ='es') returns an Error:
TypeError: 'NoneType' object is not iterable
It looks like it has to do with the gender-specific translate. As "modern" in spanish is "moderna" and "moderno" depending on the gender

@MFRS
Copy link

MFRS commented Jul 19, 2022

No one ever updated this thread, so I discovered this from stackoverflow, but this issue has already been solved.
If you do "pip install googletrans==3.1.0a0" it will give you the first result of a gender-specific translate, no longer giving you this error.

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

@DanialPahlavan
Copy link

No one ever updated this thread, so I discovered this from stackoverflow, but this issue has already been solved. If you do "pip install googletrans==3.1.0a0" it will give you the first result of a gender-specific translate, no longer giving you this error.

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

The version googletrans==3.1.0a0 has this problem too .

@rodfranck
Copy link

Still an issue. Other examples:

translator.translate('ALPINE', src='en', dest='es')
translator.translate('Armenian', src='en', dest='es')

@edisonnery
Copy link

I don`t know if someone explains here what is the source of this problem.

I mapped that it happens when the translation returns two or more options.

An example is the word "Automatic". When this word is translated for Portuguese without context can return two options, "Automático" or "Automática".

I think that you can create a parameter to define which genre the code needs to return male or female.

@sachin-suresh-rapyuta
Copy link

Was there any solution to this error, other than the try block suggested here?

@ventz
Copy link

ventz commented Apr 14, 2023

@MFRS Thank you - worked perfectly!

@vTuanpham
Copy link

No one ever updated this thread, so I discovered this from stackoverflow, but this issue has already been solved. If you do "pip install googletrans==3.1.0a0" it will give you the first result of a gender-specific translate, no longer giving you this error.

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

@MFRS This work for me, be sure to restart session if you are running on colab

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

No branches or pull requests