Certbot fails to create certificates with nginx when there is non-ascii characters in config files when using python 2.7 and CentOS 7.5

Certbot fails to create certificates with nginx when there is non-ascii characters in config files when using python 2.7 and CentOS 7.5. In my case there is non-ascii characters also in relevant parts of configuration like server_name fields, so removing non-ascii characters is not an option.

I have resolved issues by changing parser.py to use io.open instead of default open with encoding set as UTF-8 (ie. io.open(item, “r”, encoding=‘utf-8’)). And also use unicode instead of str in nginxparser.py. This solution should work with Python 2.6 and later.

However, I’m not sure if this solution is generic enough to be added to official package. So, I created this topic to discuss this matter further.

https://github.com/certbot/certbot/projects/2 :frowning:

1 Like

Couldn't those be written with the xn-- notation ?

Might be possible. Anyway, it’s not obvious for certbot user that some special notation is mandatory in configuration files.

So, I think it would be better to handle non-ascii characters in the scripts if possible. One approach is to use UTF-8 in all processing. In Linux environments it’s sensible to assume UTF-8 encoded configuration files. For my knowledge Python 3 uses io.open as default and in version 2.6 and later it’s possible to use it explicitly instead of default. So, the problem lies in with versions before 2.6, where codecs.open is possible, but obsolete in 3.x.

I think you're right and the certbot team agree, as linked by @_az there is work in progress, but it's a lot of work:

Yep, I understand and appreciate your work. I’ll post diffs of my changes if it helps your effort.

nginxparser.py.diff:

134c134
<     return str(RawNginxDumper(blocks.spaced))
---
>     return unicode(RawNginxDumper(blocks.spaced))

parser.py.diff:

9c9
< 
---
> import io
206c206
<                 with open(item) as _file:
---
>                 with io.open(item, "r", encoding='utf-8') as _file:
245c245
<                 with open(filename, 'w') as _file:
---
>                 with io.open(filename, 'w', encoding='utf-8') as _file:
410c410
<             with open(ssl_options) as _file:
---
>             with io.open(ssl_options, "r", encoding='utf-8') as _file:
1 Like

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