obynio / certbot-plugin-gandi

Certbot plugin for authentication using Gandi LiveDNS
https://pypi.org/project/certbot-plugin-gandi/
MIT License
195 stars 27 forks source link

module 'urllib' has no attribute 'quote' #3

Closed markebjones closed 5 years ago

markebjones commented 5 years ago

I get an error when I run this command with Python 3.6.7 installed on Ubuntu 18:

certbot certonly -a certbot-plugin-gandi:dns --certbot-plugin-gandi:dns-credentials gandi.ini -d domain.com -d \*.domain.com --server https://acme-v02.api.letsencrypt.org/directory

Error message:

Encountered exception during recovery: 
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/certbot/auth_handler.py", line 75, in handle_authorizations
    resp = self._solve_challenges(aauthzrs)
  File "/usr/local/lib/python3.6/dist-packages/certbot/auth_handler.py", line 132, in _solve_challenges
    resp = self.auth.perform(all_achalls)
  File "/usr/local/lib/python3.6/dist-packages/certbot/plugins/dns_common.py", line 57, in perform
    self._perform(domain, validation_domain_name, validation)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/main.py", line 48, in _perform
    error = gandi_api.add_txt_record(self._get_gandi_config(), domain, validation_name, validation)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 89, in add_txt_record
    return _update_record(cfg, domain, name, requester)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 69, in _update_record
    base_domain = _get_base_domain(cfg, domain)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 48, in _get_base_domain
    response = _request(cfg, 'GET', ('domains', candidate_base_domain))
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 42, in _request
    url = _get_url(*segs)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 36, in _get_url
    '/'.join(urllib.quote(seg, safe='') for seg in segs)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 36, in <genexpr>
    '/'.join(urllib.quote(seg, safe='') for seg in segs)
AttributeError: module 'urllib' has no attribute 'quote'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/certbot/error_handler.py", line 108, in _call_registered
    self.funcs[-1]()
  File "/usr/local/lib/python3.6/dist-packages/certbot/auth_handler.py", line 316, in _cleanup_challenges
    self.auth.cleanup(achalls)
  File "/usr/local/lib/python3.6/dist-packages/certbot/plugins/dns_common.py", line 76, in cleanup
    self._cleanup(domain, validation_domain_name, validation)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/main.py", line 54, in _cleanup
    error = gandi_api.del_txt_record(self._get_gandi_config(), domain, validation_name)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 97, in del_txt_record
    return _update_record(cfg, domain, name, requester)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 69, in _update_record
    base_domain = _get_base_domain(cfg, domain)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 48, in _get_base_domain
    response = _request(cfg, 'GET', ('domains', candidate_base_domain))
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 42, in _request
    url = _get_url(*segs)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 36, in _get_url
    '/'.join(urllib.quote(seg, safe='') for seg in segs)
  File "/usr/local/lib/python3.6/dist-packages/certbot_plugin_gandi/gandi_api.py", line 36, in <genexpr>
    '/'.join(urllib.quote(seg, safe='') for seg in segs)
AttributeError: module 'urllib' has no attribute 'quote'
An unexpected error occurred:
AttributeError: module 'urllib' has no attribute 'quote'
Please see the logfiles in /var/log/letsencrypt for more details.

I think it's similar to this but I'm not sure. Any ideas how to resolve?

obynio commented 5 years ago

Yeah, kind of. That's because urllib is the worst thing on earth to use for Python 2/3 compatible code. After digging through the code it appears that requests already handle the encoding for me.

I just committed the fix. Can you confirm that it works @markebjones ?

obynio commented 5 years ago

I also took the opportunity to release it on PyPI https://pypi.org/project/certbot-plugin-gandi/

markebjones commented 5 years ago

Awesome. Thanks! I will test it at the weekend and let you know how it goes. :)

markebjones commented 5 years ago

Tested this today and works perfectly. Thank you.

I forgot to update the plugin through pip, which confused me for a few minutes.

I've added the update command to a README file in pull request, and fixed a typo in one of the commands.

Feel free to do with that what you like. :)