Comments (5)
I added some debug lines to utils.py
def format_json(original):
# save state
states = []
text = original
LOGGER.debug("\n text: %s", text)
The output seems to indicate the following: for text with umlaut, r.text from requests is not valid (not jason data): <title>Error 403 (Forbidden)!!1</title>
I do hope you'll be able to fix it.
$ python trans_clipboard.py
Mädchen
requests.packages.urllib3.connectionpool-connectionpool.py[ln:805]:INFO: Starting new HTTPS connection (1): translate.google.cn
requests.packages.urllib3.connectionpool-connectionpool.py[ln:401]:DEBUG: "GET /translate_a/single?client=t&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&hl=zh-CN&ie=UTF-8&oe=UTF-8&otf=1&q=M%C3%A4dchen&sl=de&ssel=0&tk=651525.1024958&tl=zh-CN&tsel=0 HTTP/1.1" 403 1841
googletrans.client-client.py[ln:89]:DEBUG: from_cache: False
googletrans.utils-utils.py[ln:33]:DEBUG:
text:
403. That’s an error.
Your client does not have permission to get URL /translate_a/single?client=t&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&hl=zh-CN&ie=UTF-8&oe=UTF-8&otf=1&q=M%C3%A4dchen&sl=de&ssel=0&tk=651525.1024958&tl=zh-CN&tsel=0
from this server. That’s all we know.
Traceback (most recent call last):
File "trans_clipboard.py", line 18, in
pyperclip.copy(translator.translate(text, src='de', dest=dest).text)
File "D:\Python34\lib\site-packages\googletrans\client.py", line 149, in translate
data = self._translate(text, dest, src)
File "D:\Python34\lib\site-packages\googletrans\client.py", line 91, in translate
data = utils.format_json(r.text)
File "D:\Python34\lib\site-packages\googletrans\utils.py", line 57, in format_json
converted = json.loads(text)
File "D:\Python34\lib\json_init.py", line 318, in loads
return _default_decoder.decode(s)
File "D:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
$ python trans_clipboard.py
Machen
requests.packages.urllib3.connectionpool-connectionpool.py[ln:805]:INFO: Starting new HTTPS connection (1): translate.google.cn
requests.packages.urllib3.connectionpool-connectionpool.py[ln:401]:DEBUG: "GET /translate_a/single?client=t&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&hl=zh-CN&ie=UTF-8&oe=UTF-8&otf=1&q=Machen&sl=de&ssel=0&tk=88832.461243&tl=zh-CN&tsel=0 HTTP/1.1" 200 None
googletrans.client-client.py[ln:89]:DEBUG: from_cache: False
googletrans.utils-utils.py[ln:33]:DEBUG:
text: [[["使","Machen",null,null,0],[null,null,"Shǐ"]],null,"de",null,null,[["Machen",null,[["使",539,false,false],["让",281,false,fals
e],["令",115,false,false],["做",49,false,false],["使得",14,false,false]],[[0,6]],"Machen",0,1]],1,null,[["de"],null,[1],["de"]],null,null,null
,null,null,[["fertig machen","sauber machen","rückg\xe4ngig machen","bekannt machen","aufmerksam machen","kaputt machen","Urlaub machen","deu tlich machen","sich Sorgen machen","Sorgen machen"]]]
使
from py-googletrans.
This is because of the invalid token. It will take some time to fix this issue. Please wait a moment.
from py-googletrans.
remove_accents from EDIT in the thrid answer in http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string
Seems to do the trick in the meantime... I was doing replace(umlauts, ae|oe|ue) for German, but remove_accents is much cleaner... and works for French as well...
# -*- coding: utf-8 -*-
import unicodedata
def remove_accents(input_str):
nfkd_form = unicodedata.normalize('NFKD', input_str)
return u"".join([c for c in nfkd_form if not unicodedata.combining(c)])
if __name__ == '__main__':
from googletrans import Translator
dest = 'zh-CN'
translator = Translator()
googletrans_text = lambda x: translator.translate(x, dest=dest).text
text = 'Tatsächlich stimmten die Diagnosen der zuvor behandelnden Ärzte in nur zwölf Prozent (36 Fälle)'
print(googletrans_text(remove_accents(text)))
text = 'Une grande partie du camp d’accueil de migrants de la Linière, ouvert en mars 2016 à Grande-Synthe (Nord), a été ravagée par un incendie dans la nuit de lundi à mardi.'
print(googletrans_text(remove_accents(text)))
from py-googletrans.
remove_accents cant handle "Weiß".
There can be other cases ……
from py-googletrans.
I'm trying to fix this issue as soon as possible but it may take some time to fix this issue as this is related to the token generator.
from py-googletrans.
Related Issues (20)
- result.extra_data['possible-mistakes'] returns error HOT 1
- when i run the demo code, raise a error as following: HOT 3
- googletrans conflict with python-telegram-bot because of httpx package HOT 7
- Delete this Post
- Incorrect Translattion
- Error when translating text HOT 1
- Missing 1 required positional argument: 'client' ERROR
- Dependancy error. when installing for Python 3.11.7 32BIT
- There is an error in translating "cat" into French HOT 1
- If you have httpx dependency relevant issues go to the below project to address your problem HOT 1
- Deprecated project, no longer working, cannot even detect English HOT 1
- AttributeError: 'None type' object has no attribute 'group' HOT 5
- always return the source text! HOT 2
- Outdated httpx version HOT 10
- Different translation result vs Google Trans Website HOT 2
- wrong name
- Error "python setup.py egg_info did not run successfully" while installing googletrans==3.1.0a0
- Current GT language list HOT 2
- googletrans not translating English paragraph to French. Error is internal and inconsistent
- Batch translation is not working in 4.0.0rc1 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py-googletrans.