【发布时间】:2020-12-13 19:39:22
【问题描述】:
我目前正在使用 Python 3.8.5 开发翻译器,但没有得到合适的结果。 到目前为止我的代码是
from googletrans import Translator
text = '''Vous êtes français'''
translator = Translator()
dt = translator.detect(text)
print(dt)
在我的终端中,我应该获取源和目标
这是 Source 的 fr 和 dt 的 en 但我得到的是这个错误,我不知道如何修复。
Traceback (most recent call last):
File "c:/Users/Akash/Desktop/Learning python/Project10-MegaProject-Translator.py", line 5, in <module>
dt = translator.detect(text)
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\googletrans\client.py", line 255, in detect
data = self._translate(text, 'en', 'auto', kwargs)
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\googletrans\gtoken.py", line 54, in _update
r = self.client.get(self.host)
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpx\_client.py", line 755, in get
return self.request(
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpx\_client.py", line 600, in request
return self.send(
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpx\_client.py", line 620, in send
response = self.send_handling_redirects(
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpx\_client.py", line 647, in send_handling_redirects
response = self.send_handling_auth(
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpx\_client.py", line 684, in send_handling_auth
response = self.send_single_request(request, timeout)
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpx\_client.py", line 714, in send_single_request
) = transport.request(
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpcore\_sync\connection_pool.py", line 152, in request
response = connection.request(
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpcore\_sync\connection.py", line 65, in request
self.socket = self._open_socket(timeout)
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpcore\_sync\connection.py", line 85, in _open_socket
return self.backend.open_tcp_stream(
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpcore\_backends\sync.py", line 139, in open_tcp_stream
return SyncSocketStream(sock=sock)
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\Akash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\httpcore\_exceptions.py", line 12, in map_exceptions
raise to_exc(exc) from None
httpcore._exceptions.ConnectTimeout: _ssl.c:1106: The handshake operation timed out
PS C:\Users\Akash\Desktop\Learning python>
【问题讨论】:
-
检查您的连接。愿您的 VPN 或代理阻止网络