もしじるし

エンジニアとしての学び。人生の気付き。憧れの人へ出会うまでの道のり。

git pull,push,clone時に403エラーが出たときの対処法

仕事中に遭遇したので備忘録として

エラー内容

$ git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/xxxxxxxx
Cloning into 'Test'...
fatal: unable to access 'https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/xxxxxxxx/': The requested URL returned error: 403

発生原因

続きを読む

GCPデプロイ時にERROR: gcloud crashed (UnicodeEncodeError): 'ascii' codec can't encode characters in position 1267-1299: ordinal not in range(128)と出たときの対処方法

Google Cloud Platform(GCP)のAPP Engineにデプロイしようとした際にエラーが出たのでその対処法メモです。

環境

  • Windows10 64bit 1903

エラー内容

Beginning deployment of service [default]... Building and pushing image for service [default] ERROR: gcloud crashed (UnicodeEncodeError): 'ascii' codec can't encode characters in position 1267-1299: ordinal not in range(128)

If you would like to report this issue, please run the following command: gcloud feedback

To check gcloud for common problems, please run the following command: gcloud info --run-diagnostics

このようなエラーが発生。

原因

続きを読む

Python3 キーワード引数として扱いたいが必須項目にしたい

シチュエーション

関数定義においてキーワード引数として扱いたいが必須項目にしたいとき。

結論

befor

def hoge(name, greetings=None, ending=None):
    if greetings is ending is None:
        print('引数が足りません')
        return
    print(f'{greetings}。私の名前は{name}{ending}。')

hoge('みなみ')
# >> 引数が足りません

hoge('みなみ', greetings='こんにちはー', ending='でーす')
# >> こんにちはー。私の名前はみなみでーす。
続きを読む

Pythonで仮想環境を作成する

何回も調べるのでそろそろまとめようかと思った次第

なぜ仮想化をするのか

仮想化を行うことでプロジェクトごとに必要最低限のPythonパッケージを使用することができる。
そんなことしなくてもよい!と思われるかもしれないが以下のような場面で重宝する。

  • モジュール同士で衝突が起こっているが、片方はこのプロジェクトには使用していない。ただし、別のプロジェクトでは使用している。

滅多にないが、滅多にないからこそ発生した時の代償は重い。

結論

venvを使用する。自分が作業を行うフォルダに移動し、コマンドプロンプトで以下を入力。

python -m venv [name]

[name]は任意の名前

ちょこっと解説

コマンドライン引数
-m : sys.path から指定されたモジュール名のモジュールを探し、その内容を main モジュールとして実行します。
1. コマンドラインと環境 — Python 3.7.3 ドキュメント

venvは仮想環境を作成するモジュール。

docs.python.org

元々はpyvenvという名前だったようだけど、Python 3.6以降では非推奨になったみたい。
名前はvenvが一般的?

コードを実行すると[name]に入力した値と同じ名前のフォルダができる。

仮想環境に切り替える(有効にする)

.\[name]\Scripts\activate

実行しフォルダ名の後ろに(venv)と出たら成功。

(venv) C:\workspace\>

Building native extensions. This could take a while...と出てrailsがインストールできなかった

Railsインストールできない問題

特にWindows民にとっては。Pythonはインストローラーでいい感じになるのに。なんでや・・・。

と愚痴を言っても仕方ないので解決策を。

環境

エラー内容

Building native extensions. This could take a while...
/home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/ext/builder.rb:76: warning: Insecure world writable dir /home/Username/.rbenv/versions in PATH, mode 040777
ERROR:  Error installing nokogiri:
        ERROR: Failed to build gem native extension.

    current directory: /home/Username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.3/ext/nokogiri
/home/Username/.rbenv/versions/2.6.3/bin/ruby -I /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20190530-21712-ay2hde.rb extconf.rb
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/Username/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
        --help
        --clean
/home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
        from /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:532:in `with_werror'
        from /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
        from extconf.rb:138:in `nokogiri_try_compile'
        from extconf.rb:162:in `block in add_cflags'
        from /home/Username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/mkmf.rb:643:in `with_cflags'
        from extconf.rb:161:in `add_cflags'
        from extconf.rb:416:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/Username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/Username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.3 for inspection.
Results logged to /home/Username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/nokogiri-1.10.3/gem_make.out

以下を実行

sudo apt-get install libxslt-dev build-essential ruby-dev zlib1g-dev liblzma-dev libxmlsec1-dev libxml2-dev

これでbundle installすればインストールできます。

Windwos Helloで「カメラをオンにできませんでした。」となった場合の対処法(の一つ)

Windows Hello(カメラログイン)が使えなくなった

SurfaceProを購入し、早1か月ほど。なにも問題なく使えていたけれど、突然顔認証ログインが使用できなくなった。
WindwosUpdateの影響かと思われたけれど、調べても同じ事象の人は見つけられず。
それならばウイルス対策ソフトかな?と思ったらその通りであった。

環境

  • OS:Windows10 Home 1809 OSビルドは17763.437
  • セキュリティソフト:ESET 12.0.31.0

事象

カメラをオンにできませんでした。PINを使ってサインオンしてください。

PCの電源を入れ、ログイン画面になると以上のメッセージが出てくる。

対応

右下のESETアイコンをクリック

以下の順でクリックしていく

ESET => 設定 => コンピューター保護 => Webカメラアクセス制御の右にある歯車 => ルール 編集

アプリケーションがC:\Windows\System32\svchost.exeの項目をアクセスの許可に変更

OKを押して適用後に確認してみてください。

あとがき

PCトラブルにおける決まり文句、「何もしていないのに動かなくなった!」の典型的な例
ウイルスセキュリティを疑え。という知識があったため早期対応ができた。

googleクラウド(GCP)を使用してマイクラのマルチサーバーを構築する

GCPでマイクラサーバーを立ち上げる

続きを読む