Certbot: 无法运行certbot --nginx-UnicodeDecodeError:'ascii'

创建于 2017-11-12  ·  14评论  ·  资料来源: certbot/certbot

我的操作系统是(包括版本):

ArchLinux(内核4.13.11-1)

我安装了Certbot(certbot-auto,OS软件包管理器,pip等):

pacman -S cerbot-nginx

我运行了此命令,并产生了以下输出:

cerbot --nginx

Certbot的行为与我的预期不同,因为:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
An unexpected error occurred:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 330: ordinal not in range(128)
Please see the logfiles in /var/log/letsencrypt for more details.

这是显示问题的Certbot日志(如果有):

2017-11-12 15:15:18,497:DEBUG:certbot.main:certbot version: 0.19.0
2017-11-12 15:15:18,499:DEBUG:certbot.main:Arguments: ['--nginx']
2017-11-12 15:15:18,500:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#manual,PluginEntryPoint#nginx,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2017-11-12 15:15:18,529:DEBUG:certbot.log:Root logging level set at 20
2017-11-12 15:15:18,531:INFO:certbot.log:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2017-11-12 15:15:18,532:DEBUG:certbot.plugins.selection:Requested authenticator nginx and installer nginx
2017-11-12 15:15:18,557:DEBUG:certbot.log:Exiting abnormally:
Traceback (most recent call last):
  File "/usr/bin/certbot", line 11, in <module>
    load_entry_point('certbot==0.19.0', 'console_scripts', 'certbot')()
  File "/usr/lib/python3.6/site-packages/certbot/main.py", line 861, in main
    return config.func(config, plugins)
  File "/usr/lib/python3.6/site-packages/certbot/main.py", line 685, in run
    installer, authenticator = plug_sel.choose_configurator_plugins(config, plugins, "run")
  File "/usr/lib/python3.6/site-packages/certbot/plugins/selection.py", line 189, in choose_configurator_plugins
    authenticator = installer = pick_configurator(config, req_inst, plugins)
  File "/usr/lib/python3.6/site-packages/certbot/plugins/selection.py", line 25, in pick_configurator
    (interfaces.IAuthenticator, interfaces.IInstaller))
  File "/usr/lib/python3.6/site-packages/certbot/plugins/selection.py", line 77, in pick_plugin
    verified.prepare()
  File "/usr/lib/python3.6/site-packages/certbot/plugins/disco.py", line 248, in prepare
    return [plugin_ep.prepare() for plugin_ep in six.itervalues(self._plugins)]
  File "/usr/lib/python3.6/site-packages/certbot/plugins/disco.py", line 248, in <listcomp>
    return [plugin_ep.prepare() for plugin_ep in six.itervalues(self._plugins)]
  File "/usr/lib/python3.6/site-packages/certbot/plugins/disco.py", line 130, in prepare
    self._initialized.prepare()
  File "/usr/lib/python3.6/site-packages/certbot_nginx/configurator.py", line 156, in prepare
    self.parser = parser.NginxParser(self.conf('server-root'))
  File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 35, in __init__
    self.load()
  File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 42, in load
    self._parse_recursively(self.config_root)
  File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 53, in _parse_recursively
    trees = self._parse_files(filepath)
  File "/usr/lib/python3.6/site-packages/certbot_nginx/parser.py", line 203, in _parse_files
    parsed = nginxparser.load(_file)
  File "/usr/lib/python3.6/site-packages/certbot_nginx/nginxparser.py", line 122, in load
    return loads(_file.read())
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 330: ordinal not in range(128)
2017-11-12 15:15:18,560:ERROR:certbot.log:An unexpected error occurred:

这是我正在配置的域的相关nginx服务器块或Apache虚拟主机:

user http;
worker_processes auto;
worker_cpu_affinity auto;
pcre_jit on;

events {
    worker_connections 2048;
}


http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    tcp_nopush on;
    aio threads;
    server_tokens off; # Security: Disables nginx version in error messages and in the “Server” response header field.
    charset utf-8; # Force usage of UTF-8
    index index.php index.html index.htm;
    server {
      listen 80;
      listen [::]:80;
      server_name domain.tld;
      root /usr/share/nginx/html;
      location / {
        index index.htm index.html;
      }

      # ACME challenge
      location ^~ /.well-known/acme-challenge/ {
        default_type "text/plain";
        root /var/lib/letsencrypt;
      }
    }
}
encodintype error nginx bug

最有用的评论

在读取@egberts用户对另一个线程的注释之后,我运行了以下命令:

grep -r -P '[^\x00-\x7f]' /etc/apache2 /etc/letsencrypt /etc/nginx

该命令在注释的一个.conf文件中找到了令人反感的字符“´”。 删除它(您可以根据需要编辑评论)并重新加载nginx之后,一切又恢复了。

所有14条评论

我们将对此进行研究,因为它肯定是我们应该处理的事情,但是要解决此问题,请替换server_tokens指令注释中的双引号: “Server”

@joohoi

2018-05-05 12:28:44,181:调试:certbot.main :certbot版本:0.22.2
2018-05-05 12:28:44,181:调试:certbot.main :参数:['--nginx']
2018-05-05 12:28:44,181:调试:certbot.main :已发现的插件:PluginsRegistry(PluginEntryPoint#manual,PluginEntryPoint#nginx,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntryPoint#webroot)
2018-05-05 12:28:44,193:调试:certbot.log :根日志记录级别设置为20
2018-05-05 12:28:44,193: INFO:certbot.log :将调试日志保存到/var/log/letsencrypt/letsencrypt.log
2018-05-05 12:28:44,194:调试:certbot.plugins.selection :请求的身份验证器Nginx
2018-05-05 12:28:44,343:调试:certbot.log :异常退出:
追溯(最近一次通话):
文件“ / usr / bin / certbot”,第11行,在
load_entry_point('certbot == 0.22.2','console_scripts','certbot')()
主目录中的文件“ /usr/lib/python3/dist-packages/certbot/main.py”,行1266
返回config.func(config,plugins)
运行中的文件“ /usr/lib/python3/dist-packages/certbot/main.py”,行1018
安装程序,身份验证器= plug_sel.choose_configurator_plugins(配置,插件,“运行”)
在choice_configurator_plugins中的文件“ /usr/lib/python3/dist-packages/certbot/plugins/selection.py”,行189
Authenticator =安装程序= pick_configurator(config,req_inst,插件)
在pick_configurator中的第25行,文件“ /usr/lib/python3/dist-packages/certbot/plugins/selection.py”
(interfaces.IAuthenticator,interfaces.IInstaller)
在pick_plugin中的文件“ /usr/lib/python3/dist-packages/certbot/plugins/selection.py”,第77行
verify.prepare()
准备文件“ /usr/lib/python3/dist-packages/certbot/plugins/disco.py”,第245行
返回[plugin_ep的plugin_ep.prepare()insix.itervalues(self._plugins)]
文件“ /usr/lib/python3/dist-packages/certbot/plugins/disco.py”,第245行,位于
返回[plugin_ep的plugin_ep.prepare()insix.itervalues(self._plugins)]
准备文件“ /usr/lib/python3/dist-packages/certbot/plugins/disco.py”,第126行
self._initialized.prepare()
准备文件“ /usr/lib/python3/dist-packages/certbot_nginx/configurator.py”,第137行
self.parser = parser.NginxParser(self.conf('服务器根目录'))
__init__中的文件“ /usr/lib/python3/dist-packages/certbot_nginx/parser.py”,第38行
self.load()
加载中的文件“ /usr/lib/python3/dist-packages/certbot_nginx/parser.py”,第45行
self._parse_recursively(self.config_root)
_parse_recursively中的文件“ /usr/lib/python3/dist-packages/certbot_nginx/parser.py”,第66行
self._parse_recursively(subentry [1])
_parse_recursively中的文件“ /usr/lib/python3/dist-packages/certbot_nginx/parser.py”,第56行
树= self._parse_files(文件路径)
_parse_files中的文件“ /usr/lib/python3/dist-packages/certbot_nginx/parser.py”,行206
解析= nginxparser.load(_file)
载入中的文件“ /usr/lib/python3/dist-packages/certbot_nginx/nginxparser.py”,第123行
返回负载(_file.read())
解码中的文件“ /usr/lib/python3.4/encodings/ascii.py”,第26行
返回codecs.ascii_decode(input,self.errors)[0]
UnicodeDecodeError:'ascii'编解码器无法解码位置31的字节0xd1:序数不在范围内(128)
2018-05-05 12:28:44,346:错误:certbot.log :发生意外错误:

例如,mime类型文件包含以下行:

application/vnd.geocube+xml                     g3 g³;

g³将引发UnicodeDecodeError

> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(62)_parse_recursively()
-> elif entry[0] == ['http'] or entry[0] == ['server']:
(Pdb) l
 57             for tree in trees:
 58                 for entry in tree:
 59                     if _is_include_directive(entry):
 60                         # Parse the top-level included file
 61                         self._parse_recursively(entry[1])
 62  ->                 elif entry[0] == ['http'] or entry[0] == ['server']:
 63                         # Look for includes in the top-level 'http'/'server' context
 64                         for subentry in entry[1]:
 65                             if _is_include_directive(subentry):
 66                                 self._parse_recursively(subentry[1])
 67                             elif entry[0] == ['http'] and subentry[0] == ['server']:
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(64)_parse_recursively()
-> for subentry in entry[1]:
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(65)_parse_recursively()
-> if _is_include_directive(subentry):
(Pdb) subentry
['include', 'mime.types']
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(66)_parse_recursively()
-> self._parse_recursively(subentry[1])
(Pdb) s
--Call--
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(47)_parse_recursively()
-> def _parse_recursively(self, filepath):
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(55)_parse_recursively()
-> filepath = self.abs_path(filepath)
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(56)_parse_recursively()
-> trees = self._parse_files(filepath)
(Pdb) s
--Call--
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(189)_parse_files()
-> def _parse_files(self, filepath, override=False):
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(198)_parse_files()
-> files = glob.glob(filepath) # nginx on unix calls glob(3) for this
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(201)_parse_files()
-> trees = []
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(202)_parse_files()
-> for item in files:
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(203)_parse_files()
-> if item in self.parsed and not override:
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(205)_parse_files()
-> try:
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(206)_parse_files()
-> with open(item) as _file:
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/parser.py(207)_parse_files()
-> parsed = nginxparser.load(_file)
(Pdb) s
--Call--
> /usr/lib/python3.6/site-packages/certbot_nginx/nginxparser.py(115)load()
-> def load(_file):
(Pdb) n
> /usr/lib/python3.6/site-packages/certbot_nginx/nginxparser.py(123)load()
-> return loads(_file.read())
(Pdb) loads
<function loads at 0x7faacac85048>
(Pdb) s
--Call--
> /usr/lib/python3.6/encodings/ascii.py(25)decode()
-> def decode(self, input, final=False):
(Pdb) --KeyboardInterrupt--
(Pdb) n
> /usr/lib/python3.6/encodings/ascii.py(26)decode()
-> return codecs.ascii_decode(input, self.errors)[0]
(Pdb) n
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 10453: ordinal not in range(128)
> /usr/lib/python3.6/encodings/ascii.py(26)decode()
-> return codecs.ascii_decode(input, self.errors)[0]

感谢您的附加信息!

在读取@egberts用户对另一个线程的注释之后,我运行了以下命令:

grep -r -P '[^\x00-\x7f]' /etc/apache2 /etc/letsencrypt /etc/nginx

该命令在注释的一个.conf文件中找到了令人反感的字符“´”。 删除它(您可以根据需要编辑评论)并重新加载nginx之后,一切又恢复了。

@TommyZG您能告诉我更改哪个文件吗?

我发现当我在Windows远程环境中使用certbot-auto时,会抛出此错误,但是当我在linux远程环境中使用时,它的效果很好

我有同样的问题。 我发现以下解决方法(在Ubuntu上):

  1. 在控制台中运行:
    bash sudo locale-gen "en_US.UTF-8" sudo dpkg-reconfigure locales
  2. 将行LC_ALL="en_US.UTF-8"到文件/etc/default/locale
  3. 重新连接SSH。

完成之后,成功运行cerbot --nginx

嗨! 原因是,如果您在nginx config中有一些非ascii字母(甚至在注释中!!!),它将不起作用。

以重复的#5337结束交易,其#5341的PR。

@TommyZG您能告诉我更改哪个文件吗?

它在我的.conf文件之一中。 你还有其他人。 它在评论行中。

我遇到了类似的问题,它在/etc/nginx/conf.d/default.conf第13至17行:

# 1) limit_req  ^`^s to limit the rate of requests from one IP
# 2) limit_conn  ^`^s to limit the number of connections from one IP
# 3) client_body_timeout  ^`^s to close the connections with slow body
# 4) client_header_timeout  ^`^s to close the connections with slow headers
# 5) send_timeout  ^`^s If the client does not receive anything within this time, the connection is closed.

我删除了这些评论,并成功了。

感谢@egberts@TommyZG提供的grep提示。

✌🏻
您应该只使用其他终端。
我在使用Mac终端时遇到相同的问题,而不是我使用Windows Bash使其正常工作。

我有同样的问题。 我发现以下解决方法(在Ubuntu上):

  1. 在控制台中运行:
    shell sudo locale-gen "en_US.UTF-8" sudo dpkg-reconfigure locales
  2. 将行LC_ALL="en_US.UTF-8"到文件/etc/default/locale
  3. 重新连接SSH。

完成之后,成功运行cerbot --nginx

谢谢,对我有用。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

ohemorange picture ohemorange  ·  3评论

Mattia98 picture Mattia98  ·  3评论

schoen picture schoen  ·  3评论

DatanoiseTV picture DatanoiseTV  ·  4评论

marceliwac picture marceliwac  ·  3评论