Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled exception in translate plugin #2152

Closed
antdude opened this issue Jul 9, 2021 · 4 comments · Fixed by #2153
Closed

Unhandled exception in translate plugin #2152

antdude opened this issue Jul 9, 2021 · 4 comments · Fixed by #2153
Labels
Bug Things to squish; generally used for issues
Milestone

Comments

@antdude
Copy link

antdude commented Jul 9, 2021

Description

Sopel's translate command shows "Unexpected error
(HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max
retries exceeded with url:
/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=..."

Reproduction steps

With Sopel v7.1.1 (Python v3.9.5) running, do a translate command like:

...
10:06AM <URL> [version] Sopel v7.1.1 | Python: 3.9.5
[10:06am] <Ant> hm
10:07AM <URL> Unexpected error
          (HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max
          retries exceeded with url:
          /translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=bonne+marche
          (Caused by
          ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection
          object at 0x7f13019115e0>, 'Connection to translate.googleapis.com
          timed out. (connect timeout=40)'))) from Ant at 2021-07-09
          17:07:18.333177. Message was: .translate bonne marche
10:07AM <URL> Unexpected error
          (HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max
          retries exceeded with url:
          /translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=hormiga (Caused
          by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection
          object at 0x7f13018930d0>, 'Connection to translate.googleapis.com
          timed out. (connect timeout=40)'))) from Ant at 2021-07-09
          17:07:30.771072. Message was: .translate hormiga
...

Expected behavior

It should give me a non-error result of translation like:

...
[08:12am] <Ant> .translate hormiga
08:12AM <URL> [translate] "ant" (es to en, translate.google.com)
...

Logs

[2021-07-09 10:17:09,685] sopel.bot            ERROR    - Unexpected error (HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max retries exceeded with url: /translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=hormiga (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7f379c6ddd00>, 'Connection to translate.googleapis.com timed out. (connect timeout=40)'))) from Ant at 2021-07-09 17:17:09.685340. Message was: .translate hormiga
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/urllib3/connection.py", line 156, in _new_conn
    conn = connection.create_connection(
  File "/usr/lib/python3.9/site-packages/urllib3/util/connection.py", line 84, in create_connection
    raise err
  File "/usr/lib/python3.9/site-packages/urllib3/util/connection.py", line 74, in create_connection
    sock.connect(sa)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 376, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.9/site-packages/urllib3/connection.py", line 300, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.9/site-packages/urllib3/connection.py", line 161, in _new_conn
    raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.VerifiedHTTPSConnection object at 0x7f379c6ddd00>, 'Connection to translate.googleapis.com timed out. (connect timeout=40)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3.9/site-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max retries exceeded with url: /translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=hormiga (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7f379c6ddd00>, 'Connection to translate.googleapis.com timed out. (connect timeout=40)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ant/.local/lib/python3.9/site-packages/sopel/bot.py", line 757, in call_rule
    rule.execute(sopel, trigger)
  File "/home/ant/.local/lib/python3.9/site-packages/sopel/plugins/rules.py", line 1057, in execute
    exit_code = self._handler(bot, trigger)
  File "/home/ant/.local/lib/python3.9/site-packages/sopel/modules/translate.py", line 174, in tr2
    msg, src = translate(phrase, src, dest)
  File "/home/ant/.local/lib/python3.9/site-packages/sopel/modules/translate.py", line 59, in translate
    result = requests.get(url, params=query, timeout=40, headers=headers).text
  File "/usr/lib/python3.9/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3.9/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 504, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max retries exceeded with url: /translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=hormiga (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7f379c6ddd00>, 'Connection to translate.googleapis.com timed out. (connect timeout=40)'))

Environment

  • Sopel .version: [7.1.1]
  • Sopel installed via: [pip]
  • Python version: [3.9.5]
  • Operating system: [Fedora v33]
  • IRCd /version: [ircd-ratbox-3.0.8(20121231_3-27427)]
  • Relevant plugins: [defaults from sopel's packages via pip install]

Notes

I do not have su(do)/root access so it is done locally in my local Linux account. :)

@antdude antdude added the Bug Things to squish; generally used for issues label Jul 9, 2021
@Exirel
Copy link
Contributor

Exirel commented Jul 9, 2021

  • Bug on our part: not properly handling connection error; a user-friendly error message should be replied
  • Not a bug on our part: I think your server can't connect to or is blocked by the google translate API

@antdude
Copy link
Author

antdude commented Jul 9, 2021

Thank you for the quick answer. I wonder why sometimes it works and sometimes it doesn't.

@Exirel
Copy link
Contributor

Exirel commented Jul 9, 2021

sometimes it doesn't.

The timeout error is clearly a network error between your server and the google translate API. Nothing we (Sopel) can do about it. You'll have to ask your hosting service for that.

@antdude
Copy link
Author

antdude commented Jul 9, 2021

OK.

@dgw dgw changed the title Sopel's translate command shows "Unexpected error (HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max retries exceeded with url: /translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=..." Unhandled exception in translate plugin Jul 9, 2021
@dgw dgw added this to the 7.1.2 milestone Jul 9, 2021
@dgw dgw closed this as completed in #2153 Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Things to squish; generally used for issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants