【问题标题】:ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1123)
【发布时间】:2020-12-09 16:22:43
【问题描述】:

我正在尝试将文本翻译成英文,并且我正在使用 googletrans 包版本 = 3.0.0,Python 3.8.5。但我得到了这个错误。我使用的是公司笔记本电脑,但我没有管理员权限 谁能帮我解决这个问题?

这是我仅用于测试的代码:

from googletrans import Translator, constants 
translator = Translator()    
translation = translator.translate("Hola Mundo")

这是抛出的错误:

---------------------------------------------------------------------------
ConnectError                              Traceback (most recent call last)
<ipython-input-54-93d54b4e73a5> in <module>
      1 from googletrans import Translator, constants
      2 translator = Translator()
----> 3 translation = translator.translate("Hola Mundo")

~\Anaconda3\lib\site-packages\googletrans\client.py in translate(self, text, dest, src, **kwargs)
    180 
    181         origin = text
--> 182         data = self._translate(text, dest, src, kwargs)
    183 
    184         # this code will be updated when the format is changed.

~\Anaconda3\lib\site-packages\googletrans\client.py in _translate(self, text, dest, src, override)
     76 
     77     def _translate(self, text, dest, src, override):
---> 78         token = self.token_acquirer.do(text)
     79         params = utils.build_params(query=text, src=src, dest=dest,
     80                                     token=token, override=override)

~\Anaconda3\lib\site-packages\googletrans\gtoken.py in do(self, text)
    192 
    193     def do(self, text):
--> 194         self._update()
    195         tk = self.acquire(text)
    196         return tk

~\Anaconda3\lib\site-packages\googletrans\gtoken.py in _update(self)
     52             return
     53 
---> 54         r = self.client.get(self.host)
     55 
     56         raw_tkk = self.RE_TKK.search(r.text)

~\Anaconda3\lib\site-packages\httpx\_client.py in get(self, url, params, headers, cookies, auth, allow_redirects, timeout)
    753         timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET,
    754     ) -> Response:
--> 755         return self.request(
    756             "GET",
    757             url,

~\Anaconda3\lib\site-packages\httpx\_client.py in request(self, method, url, data, files, json, params, headers, cookies, auth, allow_redirects, timeout)
    598             cookies=cookies,
    599         )
--> 600         return self.send(
    601             request, auth=auth, allow_redirects=allow_redirects, timeout=timeout,
    602         )

~\Anaconda3\lib\site-packages\httpx\_client.py in send(self, request, stream, auth, allow_redirects, timeout)
    618         auth = self.build_auth(request, auth)
    619 
--> 620         response = self.send_handling_redirects(
    621             request, auth=auth, timeout=timeout, allow_redirects=allow_redirects,
    622         )

~\Anaconda3\lib\site-packages\httpx\_client.py in send_handling_redirects(self, request, auth, timeout, allow_redirects, history)
    645                 raise TooManyRedirects()
    646 
--> 647             response = self.send_handling_auth(
    648                 request, auth=auth, timeout=timeout, history=history
    649             )

~\Anaconda3\lib\site-packages\httpx\_client.py in send_handling_auth(self, request, history, auth, timeout)
    682         request = next(auth_flow)
    683         while True:
--> 684             response = self.send_single_request(request, timeout)
    685             if auth.requires_response_body:
    686                 response.read()

~\Anaconda3\lib\site-packages\httpx\_client.py in send_single_request(self, request, timeout)
    712                 headers,
    713                 stream,
--> 714             ) = transport.request(
    715                 request.method.encode(),
    716                 request.url.raw,

~\Anaconda3\lib\site-packages\httpcore\_sync\connection_pool.py in request(self, method, url, headers, stream, timeout)
    150 
    151             try:
--> 152                 response = connection.request(
    153                     method, url, headers=headers, stream=stream, timeout=timeout
    154                 )

~\Anaconda3\lib\site-packages\httpcore\_sync\connection.py in request(self, method, url, headers, stream, timeout)
     63                         "open_socket origin=%r timeout=%r", self.origin, timeout
     64                     )
---> 65                     self.socket = self._open_socket(timeout)
     66                 self._create_connection(self.socket)
     67             elif self.state in (ConnectionState.READY, ConnectionState.IDLE):

~\Anaconda3\lib\site-packages\httpcore\_sync\connection.py in _open_socket(self, timeout)
     83         ssl_context = self.ssl_context if scheme == b"https" else None
     84         try:
---> 85             return self.backend.open_tcp_stream(
     86                 hostname, port, ssl_context, timeout
     87             )

~\Anaconda3\lib\site-packages\httpcore\_backends\sync.py in open_tcp_stream(self, hostname, port, ssl_context, timeout)
    137                     sock, server_hostname=hostname.decode("ascii")
    138                 )
--> 139             return SyncSocketStream(sock=sock)
    140 
    141     def create_lock(self) -> SyncLock:

~\Anaconda3\lib\contextlib.py in __exit__(self, type, value, traceback)
    129                 value = type()
    130             try:
--> 131                 self.gen.throw(type, value, traceback)
    132             except StopIteration as exc:
    133                 # Suppress StopIteration *unless* it's the same exception that

~\Anaconda3\lib\site-packages\httpcore\_exceptions.py in map_exceptions(map)
     10         for from_exc, to_exc in map.items():
     11             if isinstance(exc, from_exc):
---> 12                 raise to_exc(exc) from None
     13         raise
     14 

ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123) ```

I used the same code on another laptop and I got another Error. I want to translate a text which I don't know in which language is(different files in different languages) to English and I am not sure this is the best package to use for this so even some other packages that you are using and you are sure that works would be great. Thanks


【问题讨论】:

    标签: python language-translation


    【解决方案1】:

    我不会推荐你使用这个库。正如这个库的文档中所述:

    由于 google translate 网页版的限制,此 API 不保证该库在任何时候都能正常工作。 (所以如果你不关心稳定性,请使用这个库。)

    您不考虑使用 Google 翻译 API 的官方 Google Python 客户端吗?https://cloud.google.com/translate/docs/reference/libraries/v2/python

    【讨论】:

    • 我必须为此付费,前 500 个字符是免费的,之后我必须付费。
    猜你喜欢
    • 1970-01-01
    • 2021-11-25
    • 2020-12-13
    • 1970-01-01
    • 2020-04-12
    • 2020-04-06
    • 2020-03-04
    • 1970-01-01
    • 2021-09-17
    相关资源
    最近更新 更多