3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Oracle Cloud] oci cliをupdate (python2→3) するときは、LANGに注意することを学んだ

Posted at

背景

とあるOracle Cloudを利用している社内サービスにて、運用自動化のためにoci cliを使ってスクリプトを作成していた。

oci cliを導入した時期が微妙なタイミングで、Python 2.x系で利用。
その後、Python2系のデサポートを知ったため、本番利用される前にPython 3系にアップデートしとこうと思い立つ。

Python3系へのアップデートは、以下の記事を参考にさせていただきました。
7系LinuxにPython3+OCI CLIをインストールする&2020/2/13以降はOCI CLIがサポートするPythonのバージョンが3.5+になる件

やったことは以下の2コマンドだけ。とても簡単。

※ 念のため前バージョンのディレクトリを退避後に実施

# sudo yum install -y python3
# bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"

oci cliの単体動作は問題なさそうだった。

何が起きたか

oci cliの単体動作は問題なかったが、スクリプト実行時に以下のエラーが出るようになってしまった

Traceback (most recent call last):
  File "/home/oci/bin/oci", line 8, in <module>
    sys.exit(cli())
  File "/home/oci/lib/oracle-cli/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/oci/lib/oracle-cli/lib/python3.6/site-packages/click/core.py", line 676, in main
    _verify_python3_env()
  File "/home/oci/lib/oracle-cli/lib/python3.6/site-packages/click/_unicodefun.py", line 118, in _verify_python3_env
    'for mitigation steps.' + extra)
RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment.  Consult http://click.pocoo.org/python3/for mitigation steps.

原因

調べた結果、スクリプト内の環境変数設定でLANG=Cを明示指定していたことが原因だった。
詳しくは調べ切れていないが、Python3から標準出力のエンコーディングが環境変数LANGに依存するようになったらしく、LANG=Cで実行すると上記のエラーが発生するようだ

LANG=en_US.UTF-8に変更したらエラーがでてこなくなった。このエラー以外は問題なく使えている。

3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?