Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中导入OpenSSL_Python_Python 2.7_Openssl - Fatal编程技术网

如何在python中导入OpenSSL

如何在python中导入OpenSSL,python,python-2.7,openssl,Python,Python 2.7,Openssl,我正在尝试运行以下简单代码来检索SSL证书: import ssl, socket #print ssl.get_server_certificate(('www.google.com', 443)) cert=ssl.get_server_certificate(('www.google.com', 443)) # OpenSSL x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert) x509.ge

我正在尝试运行以下简单代码来检索SSL证书:

import ssl, socket

#print ssl.get_server_certificate(('www.google.com', 443))
cert=ssl.get_server_certificate(('www.google.com', 443))
# OpenSSL
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
x509.get_subject().get_components()
但我会说:

Traceback (most recent call last):
  File "C:\Users\e\Desktop\Python\ssl\test.py", line 6, in <module>
    x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
NameError: name 'OpenSSL' is not defined
从:

对编辑的响应:
pip安装pyopenssl
应该安装六个。如果您试图自己安装,我不会这样做,但是您可以使用
pip install six cryptography
手动安装依赖项,然后您的导入应该可以正常工作。如果没有,请留下评论,我会做进一步的调查


对评论的回应:有关于的说明

pip install six或pip install requests[安全]我是windows用户。我尝试了该命令,但得到的结果是:“'pip'无法识别为内部或外部命令、可操作程序或批处理文件。”@user2192774,请键入'python-m pip install pyopenssl'。
    C:\Users\e\Desktop\Python\ssl>test.py
Traceback (most recent call last):
  File "C:\Users\e\Desktop\Python\ssl\test.py", line 2, in <module>
    from OpenSSL import SSL
  File "C:\Users\e\Desktop\Python\ssl\OpenSSL\__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "C:\Users\e\Desktop\Python\ssl\OpenSSL\rand.py", line 9, in <module>
    from six import integer_types as _integer_types
ImportError: No module named six
from OpenSSL import SSL