LoginSignup
8
5

More than 5 years have passed since last update.

cert-bot/letsencrypt nginx `UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 12: ordinal not in range(128)`

Posted at

環境

  • Amazon Linux AMI
  • nginx

事象

cert-botで証明書作ろうとしたところ下記のエラーが。

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 12: ordinal not in range(128)

原因

日本に生まれてしまったこと。

(nginxのconfファイルに日本語がコメントで書かれていた。)

対策

nginxのconfファイルの日本語を削除or英語にする。

ちなみに、nginxのconfファイルの場所は基本的に、/etc/nginx/conf.d/ 配下にある。

詳細

cert-bot内のpythonスクリプトに文字コードの宣言が書かれていないため、デフォルトのanciiで読み込まれていて、UTF-8の日本語文字列の読み込みでエラーになる。
問題のファイルはこいつ(他にもあるかも...?)。
https://github.com/certbot/certbot/blob/master/certbot-nginx/certbot_nginx/nginxparser.py

本来はこいつに

# coding: utf-8

これを追加すればいいだけなのだけど、そもそもnginxのconfigurationファイルにUTF-8で書いてるのが正しいのかどうかわからない。
テストは通るし、日本語を含むURLからのリダイレクト設定するときとかはUTF-8で保存しないと動かないからUTF-8で書くのが正しいとは思っている。(Hex表記でもいい。)
https://github.com/nginx/nginx/blob/master/src/core/ngx_string.c
この辺かな。
気が向いたらちゃんと読み込んでプルリクおくりたい。
気が向いた人ちゃんと読み込んでプルリク送ってください。

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5