我無法在python中導入ssl,它給了我一個錯誤。Python SSL導入錯誤
代碼:
import ssl
輸出(卓異文本3):
Traceback (most recent call last):
File "asd.py", line 1, in <module>
import ssl
File "/usr/lib/python2.7/ssl.py", line 138, in <module>
from socket import socket, _fileobject, _delegate_methods, error as socket_error
ImportError: cannot import name socket
我使用Linux的卡利,python的版本2.7.12+
我的source.list文件:
# deb cdrom:[Debian GNU/Linux 2016.1 _Kali-rolling_ - Official Snapshot amd64 LIVE/INSTALL Binary 20160830-11:29]/ kali-rolling contrib main non-free
#deb cdrom:[Debian GNU/Linux 2016.1 _Kali-rolling_ - Official Snapshot amd64 LIVE/INSTALL Binary 20160830-11:29]/ kali-rolling contrib main non-free
deb http://http.kali.org/kali kali-rolling main contrib non-free
deb-src http://http.kali.org/kali kali-rolling main contrib non-free
deb http://cz.archive.ubuntu.com/ubuntu yakkety main universe
deb http://http.kali.org/ /kali main contrib non-free
deb http://http.kali.org/ /wheezy main contrib non-free
命令李NE:
[email protected]:~/Desktop# python asd.py
Traceback (most recent call last):
File "asd.py", line 1, in <module>
import ssl
File "/usr/lib/python2.7/ssl.py", line 137, in <module>
from socket import socket, _fileobject, _delegate_methods, error as socket_error
ImportError: cannot import name socket
[email protected]:~/Desktop# python3 asd.py
Traceback (most recent call last):
File "asd.py", line 1, in <module>
import ssl
File "/usr/lib/python3.5/ssl.py", line 144, in <module>
from socket import socket, AF_INET, SOCK_STREAM, create_connection
ImportError: cannot import name 'socket'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
from urllib.request import urlopen
File "/usr/lib/python3.5/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.5/http/client.py", line 739, in <module>
class HTTPConnection:
File "/usr/lib/python3.5/http/client.py", line 749, in HTTPConnection
def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
AttributeError: module 'socket' has no attribute '_GLOBAL_DEFAULT_TIMEOUT'
Original exception was:
Traceback (most recent call last):
File "asd.py", line 1, in <module>
import ssl
File "/usr/lib/python3.5/ssl.py", line 144, in <module>
from socket import socket, AF_INET, SOCK_STREAM, create_connection
ImportError: cannot import name 'socket'
巨蟒的命令行:
Python 2.7.12+ (default, Aug 4 2016, 20:04:34)
[GCC 6.1.1 20160724] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "socket.py", line 1, in <module>
import ssl
File "/usr/lib/python2.7/ssl.py", line 137, in <module>
from socket import socket, _fileobject, _delegate_methods, error as socket_error
ImportError: cannot import name socket
>>> print(socket)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'socket' is not defined
>>> print(dir(socket))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'socket' is not defined
啓動python,並在其控制檯類型(每條命令在一行中):'import socket'然後'print(socket)'然後'print(dir(套接字))'並粘貼輸出。但是這個錯誤很奇怪:你在哪裏有'import ssl'語句?行號也很奇怪。你有沒有可能修改_socket.py_(來自_Python_庫)?或者你有你自己的文件_socket.py_?如果是這樣,__rename it__,因爲它是一個標準的_Python_模塊名稱。 – CristiFati
不,我沒有修改python庫..我修改了我的問題,現在你的問題的答案就在那裏。 – mfekete101
似乎您仍然在_Python_模塊搜索路徑(_asd.py_也許)旁邊有一個名爲_socket(.py/.pyc/.so)_的文件。修改_asd.py_並添加以下(4)行(在__its beginning__處):'import socket','print(socket)','import sys','print(sys.path)',並粘貼輸出任何例外)。 – CristiFati