Giter Club home page Giter Club logo

py-googletranslation's People

Contributors

saravananslb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

py-googletranslation's Issues

Exception: Unexpected status code 429

Hi @Saravananslb
Thanks for setting up a new translate library!

Unfortunately, even for a minimal working example:

from pygoogletranslation import Translator
translator = Translator()
translator.translate('Good Morning', dest='ta')

I run into this error:
Exception: Unexpected status code 429 from https://translate.google.com/_/TranslateWebserverUi/data/batchexecute after retried 3 loop with 5s delay

I upgraded to 'https://pypi.org/project/pygoogletranslation/2.0.2/' as mentioned in the closed issue, but it is still not working and throws the same error:

Exception: Unexpected status code 429 from https://translate.google.com/_/TranslateWebserverUi/data/batchexecute after retried 3 loop with 5s delay

why can't translate the full sentence?

i want to translate the sentence
aa1="Do you want beneficial technologies being shaped by your ideas? Whether in the areas of mobility solutions, consumer goods, industrial technology or energy and building technology - with us,"
translator.translate(aa1, dest='zh-cn').text
but the result is only "你想要由你的想法塑造的有益技术吗?", only output the first sentences,is this api has the length limit?

No translations returned when translating list of strings

Describe the bug
No translations returned when the request is sent from a script run as a cron job.

To Reproduce
I have a list of sentences, created dynamically, like:
list_of_strings = ['This is one sentence.', 'This is another sentence.', 'etc.']

which I send to Google with function such:

def get_mt_of_list(list_of_strings, src_lang, dest_lang):
  try:
      translations = (translator.translate(list_of_strings, src=google_tag, dest=dest_lang))
      return [xlat.text for xlat in translations]
  except Exception:
      logging.error(Exception)
      return None

My list has 130 sentences in Croatian and a bit above 6,000 characters. I call the script with src_lang='hr' and dest_lang='en'.

Expected behavior
The list of translations.

Actual behviour
When I do it manually in the python interpreter, I get the list of translations. However, when this function is run in my script (called as a cron job), I get the following in my log, 70 times:

[2021-04-06 13:05:28,303] urllib3.connectionpool@connectionpool:971 DEBUG: Starting new HTTPS connection (1): translate.google.com:443
[2021-04-06 13:05:28,348] urllib3.connectionpool@connectionpool:452 DEBUG: https://translate.google.com:443 "POST /_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&bl=boq_translate-webserver_20201207.13_p0&soc-app=1&soc-platform=1&soc-device=1&rt=c HTTP/1.1" 200 None

I get the above 70 times, and then an exception.

The 200 at the end means the request was a success (on the level of http/s), but I get an exception, not the translations. If the API accept it or not, that I don't know.

Desktop (please complete the following information):

  • OS: Ubuntu 20.04.2 LTS
  • python version: 3.8.5

Translation stopping at japanese dot (。)

Describe the bug
The Translation of text seems to stop at a japanese dot (。), which is used frequently to mark the end of a sentence. This is not the case on the google translate website, or when using regular dots.

To Reproduce
The following exerpt is from a session with python 3.8.5 and pygoogletranslation 2.0.5

❯ python
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> from pygoogletranslation import Translator
>>> t = Translator()

>>> t.translate("おはようございます。私の名前はカンナです。").text
'Good morning.'

>>> t.translate("おはようございます.私の名前はカンナです.").text
'Good morning. My name is Kanna.'

As can be seen, when using japanese dots, only the first sentence "good morning" is translated. The second sentence "My name is Kanna" is not. This is not the case when using english dots.

Expected behavior
The whole text should be translated, like it was when using english dots.

Desktop (please complete the following information):

  • OS: Manjaro Linux
  • Python: 3.8.5
  • Version 2.0.5

Incomplete translation

from pygoogletranslation import Translator # version: 2.0.5
translator = Translator()
sampleText = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
translated = translator.translate(sampleText, src="en", dest="cy")
print(translated.text)

# output: Testun ffug y diwydiant argraffu a chysodi yw Lorem Ipsum.

# output checked with 'translate.google.com': Testun ffug y diwydiant argraffu a chysodi yw Lorem Ipsum. Lorem Ipsum yw testun ffug safonol y diwydiant byth ers y 1500au, pan gymerodd argraffydd anhysbys gali o fath a'i sgramblo i wneud llyfr sbesimen math. Mae wedi goroesi nid yn unig bum canrif, ond hefyd y naid i gysodi electronig, gan aros yn ddigyfnewid yn y bôn. Cafodd ei boblogeiddio yn y 1960au gyda rhyddhau taflenni Letraset yn cynnwys darnau Lorem Ipsum, ac yn fwy diweddar gyda meddalwedd cyhoeddi bwrdd gwaith fel Aldus PageMaker gan gynnwys fersiynau o Lorem Ipsum.

json.decoder.JSONDecodeError: Expecting value: line 1 column 102 (char 101)

Hi. I am having this problem where I am not able to translate texts after some time. Maybe this is related to some api restriction?

File "/usr/local/lib/python3.8/dist-packages/pygoogletranslation/translate.py", line 73, in translate
    data = self._translate(text, src=src, dest=dest)
  File "/usr/local/lib/python3.8/dist-packages/pygoogletranslation/translate.py", line 186, in _translate
    _format_data = utils.format_response(str(response.text))
  File "/usr/local/lib/python3.8/dist-packages/pygoogletranslation/utils.py", line 64, in format_response
    li_data = json.loads(fi_data.split('pygoogletranslation')[1].replace('"[', '[').replace(']"', ']'))
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 102 (char 101)

If this is the case and is not fixable, maybe it could return some nicer message saying "you reached the daily limit" or something like that.

Thanks for considering!

同一个IP请求次数太多会导致封IP?

Describe the bug
A clear and concise description of what the bug is.
经过测试,同一个IP如果访问过于频繁,可能会导致封IP,这时候换个IP即可正常使用。

To Reproduce
Steps to reproduce the behavior:
使用这个Python库写个接口,部署到国外服务器上(如:美国),然后频繁请求这个接口,过一段时间就会报错!

Expected behavior
A clear and concise description of what you expected to happen.
部署的接口应该可以一直使用才对

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: centos、windows
  • Browser chrome

Additional context
Add any other context about the problem here.
不确定到底是不是因为IP问题导致的,但是的确换个服务器部署接口就正常了

JSONDecodeError: Expecting ',' delimiter during bulk translation

Describe the bug
During the translation of the japanese equivalent of quotes (「」), an exception is thrown over the decoding of the http response.

To Reproduce
Steps to reproduce the behavior:
Run these in a python console

from pygoogletranslation import Translator 
translator = Translator()
translator.translate('「」',src="ja",dest="en")

Expected behavior
A translated object containing quotation marks is returned

Desktop (please complete the following information):

  • OS: Windows 10
  • Version 2.0.4

Additional context
Most likely the quotation marks aren't being properly escaped during JSON decoding

Question about usage

How to use the proxy feature in Translator(proxy)? With some examples maybe...

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

How to use the proxy features?

Could you provide us some example on using the Translator(proxies=YOUR_PROXY) with actual proxy?

I've tried passing it with string and FreeProxy object from free-proxy module but none worked.

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

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

ValueError: invalid destination language

when i run print(translator.translate('good morning',dest="zh-CN")),give an error:
ValueError: invalid destination language I want to know how to replace dest if I want to translate english to chinese?

'NoneType' object has no attribute 'group'

Traceback (most recent call last):
File "c:/Users/user/Downloads/free-google-translate-master/Python/1.py", line 5, in
translator.translate('Good Morning', dest='ta')
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googletrans\gtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
This is my trace back.
i want to know how can fix the problem

ImportError: cannot import name 'TranslatedPart' from 'googletrans.models'

Describe the bug
Import error when package is imported: Import Error: cannot import name 'TranslatedPart' from 'googletrans.models'

To Reproduce
Install and import pygoogletranslation

!pip install pygoogletranslation
import pygoogletranslation
ModuleNotFoundError: No module named 'googletrans'

Package googletrans seems to be missing.

Install googletrans

!pip install googletrans
import pygoogletranslation
ImportError: cannot import name 'TranslatedPart' from 'googletrans.models' (/usr/local/lib/python3.7/dist-packages/googletrans/models.py)

Expected behavior
No import error

Desktop (please complete the following information):

  • Happens both on Google Colab and local Arch Linux installation
  • Python 3.7.10 (Google Colab), Python 3.9.2 (local), pygoogletranslation 2.0.6

Exception: Unexpected status code 429 from https://translate.googleapis.com/translate_a/

After multiple requests, this error is reported

Traceback (most recent call last):
File "D:/code/google_trans_new/tmp", line 45, in
status = (translator.translate(text, dest="zh-cn").text)
File "C:\Users\Admin\Anaconda3\envs\tf\lib\site-packages\pygoogletranslation\translate.py", line 55, in translate
data = self._translate(text, src=src, dest=dest)
File "C:\Users\Admin\Anaconda3\envs\tf\lib\site-packages\pygoogletranslation\translate.py", line 169, in _translate
raise Exception('Unexpected status code {} from {}'.format(response.status_code, self.host))
Exception: Unexpected status code 429 from https://translate.googleapis.com/translate_a/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.