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

至此,終於完成安裝了。

      記此,避免后續繼續踩坑。

 

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM