發表文章

目前顯示的是有「python」標籤的文章

ssh 出現 error in libcrypto Connection closed 錯誤訊息

 最近公司的產品OS更換到Alma Linux,因此安裝了一台全新的Alma Linux機器,然後接下來要使用scp去別的主機搬移檔案的時候出現了下面的錯誤訊息 The authenticity of host '10.*.*.68 (10.*.*.68)' can't be established. RSA key fingerprint is SHA256:RKJMaNXf4Fw5I2rjsdiLr17MQn1LTyMurlb6hV2qo18. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.*.*.68' (RSA) to the list of known hosts. ssh_dispatch_run_fatal: Connection to 10.*.*.68 port 22: error in libcrypto Connection closed 解決方法是指定加密演算法 update-crypto-policies --set DEFAULT:SHA1

Python -- 將unix timestamp 轉為字串時間之作法

當取得或處理過的unix timestamp 要轉成字串形式的資料時有下面兩個選擇 1. 依據local time 做字串轉換 from datetime import datetime import tzlocal # $ pip install tzlocal unix_timestamp = 1491372600 local_timezone = tzlocal.get_localzone() local_time = datetime.fromtimestamp(unix_timestamp, local_timezone) print(local_time.strftime("%Y-%m-%d %H:%M:%S.%f%z (%Z)")) 2. 只是單純轉換,依舊是UTC 時區 from datetime import datetime utc_time = datetime.utcfromtimestamp(unix_timestamp) print(utc_time.strftime("%Y-%m-%d %H:%M:%S.%f+00:00")) 最後附上 時常用來做驗證的線上小工具 http://www.onlineconversion.com/unix_time.htm

Centos 6.x 安裝 python 2.7 & pip

原則上這篇文章不是要將原本centos 6 預設的python 2.6 取代掉,而是將python 2.7 也並存於環境內做 2.7版本的開發 。畢竟 centos 6 有許多python的相依性是以2.6為主。 安裝步驟如下 1. 確認環境已經安裝了下面的東西 yum install zlib-devel bzip2-devel sqlite sqlite-devel openssl-devel gcc 2. 安裝python2.7 >>wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz >>tar xzvf Python-2.7.12.tgz >>./configure #careful ,if system did not install gcc , then yum install gcc first!! >>make altinstall 3. 安裝 pip wget ``--no-check-certificate`` https://bootstrap.pypa.io/get-pip.py python get-pip.py 4. 安裝 virtualenv 來做python 開發環境切換 >>pip2.7 install virtualenv 5. 建立一個python 虛擬環境目錄存放相關安裝組件 python 設定到 2.7 >>virtualenv -p python2.7 test 6. 啟用虛擬環境與關閉 啟用之前建立的虛擬目錄 >>source test/bin/activate 關閉虛擬環境 >>deactivate