TypeError: __str__ returned non-string (type Error) An unexpected error occurred:

Hi,

I am encountering TypeError: str returned non-string (type Error) An unexpected error occurred. The details are as below.

# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
# certbot --version
certbot 1.11.0
# rpm -qa | grep ca-certificates
ca-certificates-2022.2.54-74.el7_9.noarch
#

An unexpected error occurred: TypeError: str returned non-string (type Error)

cat /var/log/letsencrypt/letsencrypt.log
2023-05-22 12:59:14,424:DEBUG:certbot._internal.main:certbot version: 1.11.0
2023-05-22 12:59:14,424:DEBUG:certbot._internal.main:Location of certbot entry point: /bin/certbot
2023-05-22 12:59:14,424:DEBUG:certbot._internal.main:Arguments: ['--standalone', '--preferred-challenges', 'http', '-d', 'edge.example.mydomain.com']
2023-05-22 12:59:14,424:DEBUG:certbot._internal.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2023-05-22 12:59:14,436:DEBUG:certbot._internal.log:Root logging level set at 20
2023-05-22 12:59:14,436:INFO:certbot._internal.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2023-05-22 12:59:14,437:DEBUG:certbot._internal.plugins.selection:Requested authenticator standalone and installer None
2023-05-22 12:59:14,437:DEBUG:certbot._internal.plugins.selection:Single candidate plugin: * standalone
Description: Spin up a temporary webserver
Interfaces: IAuthenticator, IPlugin
Entry point: standalone = certbot._internal.plugins.standalone:Authenticator
Initialized: <certbot._internal.plugins.standalone.Authenticator object at 0x7f62f603fd90>
Prep: True
2023-05-22 12:59:14,437:DEBUG:certbot._internal.plugins.selection:Selected authenticator <certbot._internal.plugins.standalone.Authenticator object at 0x7f62f603fd90> and installer None
2023-05-22 12:59:14,438:INFO:certbot._internal.plugins.selection:Plugins selected: Authenticator standalone, Installer None
2023-05-22 12:59:16,294:WARNING:certbot.util:Invalid email address: .
2023-05-22 12:59:29,502:DEBUG:acme.client:Sending GET request to https://acme-v02.api.letsencrypt.org/directory.
2023-05-22 12:59:29,508:INFO:urllib3.connectionpool:Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
2023-05-22 12:59:30,100:DEBUG:certbot._internal.log:Exiting abnormally:
Traceback (most recent call last):
  File "/bin/certbot", line 9, in <module>
    load_entry_point('certbot==1.11.0', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/site-packages/certbot/main.py", line 15, in main
    return internal_main.main(cli_args)
  File "/usr/lib/python2.7/site-packages/certbot/_internal/main.py", line 1421, in main
    return config.func(config, plugins)
  File "/usr/lib/python2.7/site-packages/certbot/_internal/main.py", line 1277, in certonly
    le_client = _init_le_client(config, auth, installer)
  File "/usr/lib/python2.7/site-packages/certbot/_internal/main.py", line 652, in _init_le_client
    acc, acme = _determine_account(config)
  File "/usr/lib/python2.7/site-packages/certbot/_internal/main.py", line 570, in _determine_account
    config, account_storage, tos_cb=_tos_cb)
  File "/usr/lib/python2.7/site-packages/certbot/_internal/client.py", line 173, in register
    acme = acme_from_config_key(config, key)
  File "/usr/lib/python2.7/site-packages/certbot/_internal/client.py", line 43, in acme_from_config_key
    return acme_client.BackwardsCompatibleClientV2(net, key, config.server)
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 831, in __init__
    directory = messages.Directory.from_json(net.get(server).json())
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 1168, in get
    self._send_request('GET', url, **kwargs), content_type=content_type)
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 1118, in _send_request
    response = self.session.request(method, url, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 486, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 598, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 314, in _raise_timeout
    if 'timed out' in str(err) or 'did not complete (read)' in str(err):  # Python 2.6
TypeError: __str__ returned non-string (type Error)
2023-05-22 12:59:30,102:ERROR:certbot._internal.log:An unexpected error occurred:
2023-05-22 12:59:30,102:ERROR:certbot._internal.log:TypeError: __str__ returned non-string (type Error)

Please guide. Thanks in advance.

Best Regards,

Kaushal

1 Like

The error message is unhelpful due to you having some pretty old Python dependencies, which isn't a surprise for CentOS 7. I do recommend using the snap rather than using the Certbot package from EPEL7.

Otherwise, it would be helpful if you could try make the same request using curl:

 curl -i https://acme-v02.api.letsencrypt.org/directory
5 Likes

@_az Please refer to the below details

curl -i https://acme-v02.api.letsencrypt.org/directory
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 23 May 2023 01:09:42 GMT
Content-Type: application/json
Content-Length: 752
Connection: keep-alive
Cache-Control: public, max-age=0, no-cache
X-Frame-Options: DENY
Strict-Transport-Security: max-age=604800

{
  "9PJM61XYE7Y": "https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417",
  "keyChange": "https://acme-v02.api.letsencrypt.org/acme/key-change",
  "meta": {
    "caaIdentities": [
      "letsencrypt.org"
    ],
    "termsOfService": "https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf",
    "website": "https://letsencrypt.org"
  },
  "newAccount": "https://acme-v02.api.letsencrypt.org/acme/new-acct",
  "newNonce": "https://acme-v02.api.letsencrypt.org/acme/new-nonce",
  "newOrder": "https://acme-v02.api.letsencrypt.org/acme/new-order",
  "renewalInfo": "https://acme-v02.api.letsencrypt.org/draft-ietf-acme-ari-01/renewalInfo/",
  "revokeCert": "https://acme-v02.api.letsencrypt.org/acme/revoke-cert"
}

Please suggest further. Thanks in advance.

Best Regards,

Kaushal

1 Like

@_az Thanks for the help and much appreciated. I did the below steps to install certbot using snap package manager

#yum install snapd
#systemctl enable --now snapd.socket
#ln -s /var/lib/snapd/snap /snap
#snap install certbot --classic
#/var/lib/snapd/snap/bin/certbot --version
#ln -s /var/lib/snapd/snap/bin/certbot /usr/bin/certbot 
#certbot --version
certbot 2.6.0

#ln -s /var/lib/snapd/snap/bin/certbot /usr/bin/certbot <---- Is this step correct or are there any other recommended method to be set on CentOS Linux release 7.9.2009 (Core) using PATH variable or .....?

Please guide further.

Thanks in advance.

Best Regards,

Kaushal

1 Like

That symlink command should be fine for CentOS 7, as long as you have first removed the yum version of Certbot.

Does the snapped version of Certbot work, or at least produce a more helpful error message?

5 Likes

@_az Yes it worked perfectly. Thanks a lot and much appreciated. Any issues as per the below output for An unexpected error occurred: TypeError: str returned non-string (type Error)?

curl -i https://acme-v02.api.letsencrypt.org/directory
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 23 May 2023 01:09:42 GMT
Content-Type: application/json
Content-Length: 752
Connection: keep-alive
Cache-Control: public, max-age=0, no-cache
X-Frame-Options: DENY
Strict-Transport-Security: max-age=604800

{
  "9PJM61XYE7Y": "https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417",
  "keyChange": "https://acme-v02.api.letsencrypt.org/acme/key-change",
  "meta": {
    "caaIdentities": [
      "letsencrypt.org"
    ],
    "termsOfService": "https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf",
    "website": "https://letsencrypt.org"
  },
  "newAccount": "https://acme-v02.api.letsencrypt.org/acme/new-acct",
  "newNonce": "https://acme-v02.api.letsencrypt.org/acme/new-nonce",
  "newOrder": "https://acme-v02.api.letsencrypt.org/acme/new-order",
  "renewalInfo": "https://acme-v02.api.letsencrypt.org/draft-ietf-acme-ari-01/renewalInfo/",
  "revokeCert": "https://acme-v02.api.letsencrypt.org/acme/revoke-cert"
}

Please suggest further. Thanks in advance.

Best Regards,

Kaushal

Does that still occur when using the snap version of Certbot?

3 Likes

@Osiris It does not occur for snap version of Certbot

#certbot --version
certbot 2.6.0

Please guide further.

Thanks in advance.

Best Regards,

Kaushal

1 Like

Not sure what you mean. If the error is gone, all is good right? What guidance do you require?

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.