【问题标题】:Is there any limit on the number of request to be made to Python gtts module?对 Python gtts 模块的请求数量是否有限制?
【发布时间】:2017-04-03 14:36:56
【问题描述】:

我正在做我的大学项目,它使用 python gtts 并且我使用了 gTTS 模块(我已经使用该模块使用 gtts 将文本转换为语音)但是几天后我收到了诸如 Max retries 超出之类的错误与网址:

实际错误是:

Traceback (most recent call last):   File "C:\Python\lib\site-packages\requests\packages\urllib3\connection.py", line 135, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)   File "C:\Python\lib\site-packages\requests\packages\urllib3\util\connection.py", line 66, in create_connection
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):   File "C:\Python\lib\socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559, in urlopen
    body=body, headers=headers)   File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)   File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 782, in _validate_conn
    conn.connect()   File "C:\Python\lib\site-packages\requests\packages\urllib3\connection.py", line 215, in connect
    conn = self._new_conn()   File "C:\Python\lib\site-packages\requests\packages\urllib3\connection.py", line 144, in _new_conn
    self, "Failed to establish a new connection: %s" % e) requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000132FB57A438>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Python\lib\site-packages\requests\adapters.py", line 370, in send
    timeout=timeout   File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 609, in urlopen
    _stacktrace=sys.exc_info()[2])   File "C:\Python\lib\site-packages\requests\packages\urllib3\util\retry.py", line 271, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause)) requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000132FB57A438>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "<pyshell#3>", line 1, in <module>
    tts.save('Hello.mp3')   File "C:\Python\lib\site-packages\gtts\tts.py", line 94, in save
    self.write_to_fp(f)   File "C:\Python\lib\site-packages\gtts\tts.py", line 107, in write_to_fp
    'tk' : self.token.calculate_token(part)}   File "C:\Python\lib\site-packages\gtts_token\gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()   File "C:\Python\lib\site-packages\gtts_token\gtts_token.py", line 58, in
_get_token_key
    response = requests.get("https://translate.google.com/")   File "C:\Python\lib\site-packages\requests\api.py", line 69, in get
    return request('get', url, params=params, **kwargs)   File "C:\Python\lib\site-packages\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)   File "C:\Python\lib\site-packages\requests\sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)   File "C:\Python\lib\site-packages\requests\sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)   File "C:\Python\lib\site-packages\requests\adapters.py", line 423, in send
    raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000132FB57A438>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))

现在我想知道可能的原因和解决方法。

【问题讨论】:

    标签: python


    【解决方案1】:

    从你发布的信息来看,这与 gtts 模块的限制无关。

    您的客户收到了“超出最大重试次数”的情况,该客户试图在某处提交请求,但失败了,然后在放弃之前重试了几次。根据您粘贴的错误,您的错误是socket.gaierror: [Errno 11001] getaddrinfo failed。这意味着您不再能够找到连接到您一直连接到的主机的信息。要么您更改了代码的 hostport,要么由于某种原因,您无法再解析地址。

    查看 getaddrinfo,我没有看到它返回错误代码 11001,并且命令行实用程序 perror 也无法识别该错误代码。

    如果您没有更改主机名或端口,我的直觉是您将无法再解析主机名。您可以尝试使用nslookup 来查看是否可以解析名称。如果可以,请尝试使用给定 IP 的数字形式而不是使用域名来运行您的代码。如果 nslookup 找不到主机,则主机不再可解析。您的学校要么从其名称服务器中删除了该站点,要么该站点不再存在。

    【讨论】:

      猜你喜欢
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 2010-12-27
      • 1970-01-01
      • 2018-03-08
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多