python3安裝Crypto過程
公司app登入介面在傳參時,有個加密欄位“——key”。在使用python做介面測試時,調研可以通過Crypto包進行加密處理,而Crypto包是第三方包,需要進行安裝。
1.使用python3 -m pip install Crypto進行安裝;
結果,安裝失敗,報錯如下:
Could not fetch URL https://pypi.org/simple/crypto/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/crypto/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1122)'))) - skipping ERROR: Could not find a version that satisfies the requirement Crypto (from versions: none) ERROR: No matching distribution found for Crypto Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1122)'))) - skipping
在網上搜索解決方法後,修改了安裝命令。
2.使用命令python3 -m pip --trusted-host pypi.org install Crypto進行安裝;
結果,仍然安裝失敗,報錯如下:
ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/fc/bb/0b812dc02e6357606228edfbf5808f5ca0a675a84273578c3a199e841cd8/crypto-1.4.1-py2.py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1122)')))
繼續尋找解決方法,修改了安裝源,指定為豆瓣的映象源。
3.python3 -m pip install Crypto -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
結果,安裝成功。如下:
Installing collected packages: shellescape, pyyaml, Naked, Crypto
Successfully installed Crypto-1.4.1 Naked-0.1.31 pyyaml-5.4.1 shellescape-3.8.1
到了這一步,Crypto算是安裝成功了,但是在使用from Crypto.PublicKey import RSA匯入時,提示並沒有Crypto庫。果然不會這麼順利的,又在網上查詢解決方法。
在進到python3安裝路徑後,進到site-packages目錄,檢視包名是小寫的(crypto,crypto-1.4.1.dist-info),於是將首字母修改為大寫。
當再次匯入包時from Crypto.PublicKey import RSA,又提示沒有PublicKey,沒轍,又在網上搜索解決辦法,找到個答案說需要安裝pycryptodome。還能怎麼辦,繼續安裝唄!
4.python3 -m pip install pycryptodome-i http://pypi.douban.com/simple --trusted-host pypi.douban.com
至此,終於完成安裝了。
記此,避免後續繼續踩坑。