LinDRon
2017-06-18 01:56
采纳率: 25%
浏览 6.0k
已采纳

import socket模块出现异常

不知道是什么原因,求解决办法,感谢!!

import socket
Traceback (most recent call last):
File "", line 1, in
File "/home/python/PycharmProjects/own/internet_compile/socket.py", line 3, in
udpSocket = socket.socket()
TypeError: 'module' object is not callable
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
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in
from urllib.request import urlopen
File "/usr/lib/python3.5/urllib/request.py", line 88, in
import http.client
File "/usr/lib/python3.5/http/client.py", line 71, in
import email.parser
File "/usr/lib/python3.5/email/parser.py", line 12, in
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.5/email/feedparser.py", line 27, in
from email import message
File "/usr/lib/python3.5/email/message.py", line 16, in
from email import utils
File "/usr/lib/python3.5/email/utils.py", line 29, in
import socket
File "/home/python/PycharmProjects/own/internet_compile/socket.py", line 3, in
udpSocket = socket.socket()
TypeError: 'module' object is not callable

Original exception was:
Traceback (most recent call last):
File "", line 1, in
File "/home/python/PycharmProjects/own/internet_compile/socket.py", line 3, in
udpSocket = socket.socket()
TypeError: 'module' object is not callable

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • oyljerry 2017-06-18 04:59
    已采纳

    你的源码文件不要用socket.py,他跟系统模块名字冲突了。改个名字,比如sock_test.py

     File "/home/python/PycharmProjects/own/internet_compile/socket.py", line 3, in 
    
    已采纳该答案
    评论
    解决 7 无用
    打赏 举报
  • qmwuu 2021-02-23 09:48

    socket问题 

    报错:C:\Users\jacob\AppData\Local\Programs\Python\Python38\python.exe C:/workspace/美女下载/download.py
    Traceback (most recent call last):
      File "C:/workspace/download.py", line 18, in <module>
        a=requests.get(url,headers=headers).conent.decode('gbk')
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 76, in get
        return request('get', url, params=params, **kwargs)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
        return session.request(method=method, url=url, **kwargs)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 542, in request
        resp = self.send(prep, **send_kwargs)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 655, in send
        r = adapter.send(request, **kwargs)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 439, in send
        resp = conn.urlopen(
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
        httplib_response = self._make_request(
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
        conn.request(method, url, **httplib_request_kw)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 235, in request
        super(HTTPConnection, self).request(method, url, body=body, headers=headers)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1255, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1301, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1250, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1010, in _send_output
        self.send(msg)
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 950, in send
        self.connect()
      File "C:\Users\jacob\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 201, in connect
        conn = self._new_conn()
    TypeError: 'socket' object is not callable

    Process finished with exit code 1

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题