davidegalilei / gpytranslate Goto Github PK
View Code? Open in Web Editor NEWA Python3 library for translating text using Google Translate API.
Home Page: https://pypi.org/project/gpytranslate
License: MIT License
A Python3 library for translating text using Google Translate API.
Home Page: https://pypi.org/project/gpytranslate
License: MIT License
I'm sure I'm feeding the function normal string data, the problem is that sometimes an error occurs on the server, I have little programming experience to fully analyze and fix it, but I think sometimes the library gets an empty response that can't be steamed.
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
translation = await t.translate(str(text), targetlang=str(leng))
File "/home/simulatte/simulatte/.venv/lib/python3.8/site-packages/gpytranslate/gpytranslate.py", line 118, in translate
(
File "/home/simulatte/simulatte/.venv/lib/python3.8/site-packages/httpx/_models.py", line 854, in json
return jsonlib.loads(self.text, **kwargs)
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 1 (char 0)
TTS doesn't work at all.
I use the example from the documentation https://pypi.org/project/gpytranslate/
from gpytranslate import SyncTranslator
translator = SyncTranslator()
with open("test.mp3", "wb") as file:
translator.tts("Hello world!", file=file)
OpenSUSE Tumbleweed x86_64, Python 3.10.10, gpytranslate 1.5.1 (from pip)
>>> with open("test.mp3", "wb") as file:
... translator.tts("hello", file=file)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/nikita/.local/lib/python3.10/site-packages/gpytranslate/sync/sync_translator.py", line 197, in tts
raise TranslationError(e) from None
gpytranslate.exceptions.TranslationError: An error occurred while trying to translate/tts: TypeError("Response.iter_bytes() got an unexpected keyword argument 'chunk_size'")
Traceback (most recent call last):
File "jyh_test.py", line 37, in
translation = t.translate(tmp, targetlang="zh-CN")
File "/usr/local/lib/python3.7/site-packages/gpytranslate/sync/sync_translator.py", line 112, in translate
with httpx.Client(proxies=self.proxies, **self.options) as c:
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 670, in init
for key, proxy in proxy_map.items()
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 670, in
for key, proxy in proxy_map.items()
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 722, in _init_proxy_transport
proxy=proxy,
File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 146, in init
proxy_url=proxy.url.raw,
AttributeError: 'list' object has no attribute 'url'
Hello hello im getting this error;JSONDecodeError('Expecting value: line 1 column 1 (char 0)'). My script worked once or twice and then im getting this every time ever since, i dont get what is going on would be nice if you can help me , thanks have a great day
Iphone X ios 14.6, jupyter lab
---------------------------------------------------------------------------
TranslationError Traceback (most recent call last)
Input In [7], in <module>
22 print(f"Translation: {translation.text}\nDetected language: {language}\n\n")
25 if __name__ == "__main__":
---> 26 asyncio.run(main("mer"))
File /private/var/containers/Bundle/Application/99EF6119-3B0D-40F0-8B62-4976D61AB3FD/Carnets.app/Library/lib/python3.9/site-packages/nest_asyncio.py:38, in _patch_asyncio.<locals>.run(main, debug)
36 task = asyncio.ensure_future(main)
37 try:
---> 38 return loop.run_until_complete(task)
39 finally:
40 if not task.done():
File /private/var/containers/Bundle/Application/99EF6119-3B0D-40F0-8B62-4976D61AB3FD/Carnets.app/Library/lib/python3.9/site-packages/nest_asyncio.py:81, in _patch_loop.<locals>.run_until_complete(self, future)
78 if not f.done():
79 raise RuntimeError(
80 'Event loop stopped before Future completed.')
---> 81 return f.result()
File /private/var/containers/Bundle/Application/99EF6119-3B0D-40F0-8B62-4976D61AB3FD/Carnets.app/Library/lib/python3.9/asyncio/futures.py:201, in Future.result(self)
199 self.__log_traceback = False
200 if self._exception is not None:
--> 201 raise self._exception
202 return self._result
File /private/var/containers/Bundle/Application/99EF6119-3B0D-40F0-8B62-4976D61AB3FD/Carnets.app/Library/lib/python3.9/asyncio/tasks.py:256, in Task.__step(***failed resolving arguments***)
252 try:
253 if exc is None:
254 # We use the `send` method directly, because coroutines
255 # don't have `__iter__` and `__next__` methods.
--> 256 result = coro.send(None)
257 else:
258 result = coro.throw(exc)
Input In [7], in main(mot)
18 print(word)
19 print(type(word))
---> 20 translation = await t.translate(str(word), targetlang="fr")
21 language = await t.detect(translation.text)
22 print(f"Translation: {translation.text}\nDetected language: {language}\n\n")
File /var/mobile/Containers/Data/Application/24595BCF-2FB7-4B88-8C4D-4852824A51D5/Library/lib/python3.9/site-packages/gpytranslate/gpytranslate.py:157, in Translator.translate(self, text, sourcelang, targetlang, client, dt, dj, **extra)
155 return self.check(raw=raw, client=client, dt=dt, text=text)
156 except Exception as e:
--> 157 raise TranslationError(e) from None
TranslationError: An error occurred while trying to translate/tts: JSONDecodeError('Expecting value: line 1 column 1 (char 0)')
In [ ]:
File "G:\python\venv\lib\site-packages\gpytranslate\sync\sync_translator.py", line 114, in translate
c.post(
File "G:\python\venv\lib\site-packages\httpx\_client.py", line 824, in post
return self.request(
File "G:\python\venv\lib\site-packages\httpx\_client.py", line 600, in request
return self.send(
File "G:\python\venv\lib\site-packages\httpx\_client.py", line 620, in send
response = self.send_handling_redirects(
File "G:\python\venv\lib\site-packages\httpx\_client.py", line 647, in send_handling_redirects
response = self.send_handling_auth(
File "G:\python\venv\lib\site-packages\httpx\_client.py", line 684, in send_handling_auth
response = self.send_single_request(request, timeout)
File "G:\python\venv\lib\site-packages\httpx\_client.py", line 714, in send_single_request
) = transport.request(
File "G:\python\venv\lib\site-packages\httpcore\_sync\http_proxy.py", line 110, in request
return self._tunnel_request(
File "G:\python\venv\lib\site-packages\httpcore\_sync\http_proxy.py", line 191, in _tunnel_request
proxy_response = proxy_connection.request(
File "G:\python\venv\lib\site-packages\httpcore\_sync\connection.py", line 65, in request
self.socket = self._open_socket(timeout)
File "G:\python\venv\lib\site-packages\httpcore\_sync\connection.py", line 85, in _open_socket
return self.backend.open_tcp_stream(
File "G:\python\venv\lib\site-packages\httpcore\_backends\sync.py", line 139, in open_tcp_stream
return SyncSocketStream(sock=sock)
File "C:\Python\lib\contextlib.py", line 135, in __exit__
self.gen.throw(type, value, traceback)
File "G:\python\venv\lib\site-packages\httpcore\_exceptions.py", line 12, in map_exceptions
raise to_exc(exc) from None
httpcore._exceptions.ConnectError: EOF occurred in violation of protocol (_ssl.c:1123)
Although it requires >=3.6
in setup.py
, it is not usable in versions 3.6 and 3.7 since it is using some features implemented in 3.8+, such as typing.Literal
.
And for the testing workflow, why not using a Python version matrix to check if it is working on all Python versions?
I think maybe the text is too long?
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="https://www.google.com/sorry/index?continue=https://translate.google.com/translate_a/single%3Fclient%3Dgtx%26sl%3Dde%2
gpytranslate 1.5.1
No response
t = SyncTranslator(proxies={"https://": "https://{222.37.211.42:46603}"})
I added a proxy like this, but as long as I run it, I get an error
Fifteen thousand factories foul the italian ligurian riviera.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/http_proxy.py", line 232, in _tunnel_request
extensions=extensions,
File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/connection.py", line 136, in handle_request
self.socket = self._open_socket(timeout)
File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/connection.py", line 168, in _open_socket
local_address=self._local_address,
File "/usr/local/lib/python3.7/site-packages/httpcore/_backends/sync.py", line 144, in open_tcp_stream
return SyncSocketStream(sock=sock)
File "/usr/local/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.7/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
raise to_exc(exc) from None
httpcore.ConnectError: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
yield
File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 185, in handle_request
extensions=extensions,
File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/http_proxy.py", line 128, in handle_request
method, url, headers=headers, stream=stream, extensions=extensions
File "/usr/local/lib/python3.7/site-packages/httpcore/_sync/http_proxy.py", line 256, in _tunnel_request
raise ProxyError(exc)
httpcore.ProxyError: [Errno -2] Name or service not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "jyh_test.py", line 39, in <module>
translation = t.translate(tmp, targetlang="zh-CN")
File "/usr/local/lib/python3.7/site-packages/gpytranslate/sync/sync_translator.py", line 119, in translate
if isinstance(text, str)
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 1121, in post
timeout=timeout,
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 788, in request
request, auth=auth, allow_redirects=allow_redirects, timeout=timeout
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 883, in send
history=[],
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 912, in _send_handling_auth
history=history,
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 947, in _send_handling_redirects
response = self._send_single_request(request, timeout)
File "/usr/local/lib/python3.7/site-packages/httpx/_client.py", line 988, in _send_single_request
extensions={"timeout": timeout.as_dict()},
File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 185, in handle_request
extensions=extensions,
File "/usr/local/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.7/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ProxyError: [Errno -2] Name or service not known```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.