首页 文章

socket.error:[Errno 10013]尝试以其访问权限禁止的方式访问套接字

提问于
浏览
25

我正在尝试使用Windows 7上的Python 2.6.5创建自定义TCP堆栈,以在本地端口80上提供有效的http页面请求 . 但是,我遇到了似乎Windows 7收紧安全性的问题 . 此代码适用于Vista .

这是我的示例代码:

import SocketServer
import struct

class MyTCPHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        headerText = """HTTP/1.0 200 OK
                        Date: Fri, 31 Dec 1999 23:59:59 GMT
                        Content-Type: text/html
                        Content-Length: 1354"""
        bodyText = "<html><body>some page</body></html>"
        self.request.send(headerText + "\n" + bodyText)

if __name__ == "__main__":
    HOST, PORT = "localhost", 80
    server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
    server.serve_forever()

C:\ python> python TestServer.py Traceback(最近一次调用最后一次):文件“TestServer.py”,第19行,在server = SocketServer.TCPServer((HOST,PORT),MyTCPHandler)文件“C:\ Python26 \ lib \ SocketServer.py“,第400行,在init self.server_bind()文件”C:\ Python26 \ lib \ SocketServer.py“,第411行,在server_bind self.socket.bind(self.server_address)文件”“中,第1行,在bind socket.error中:[Errno 10013]尝试以其访问权限禁止的方式访问套接字

我究竟如何在Windows 7上使用它?

[编辑于2010年5月5日@ 2344 PDT] answer解释说,该错误是由于在访问低于1024的端口时需要提升/超级用户权限引起的 . 我是访问端口80的 .

10 回答

  • 2

    对我来说,当我有另一个进程已经在同一个端口上侦听时,它就像在Windows 7 x64上一样抱怨 .

    通过运行可以查看当前占用(绑定)的端口

    netstat -ban
    
  • 8

    在Windows Vista / 7上,使用UAC,管理员帐户默认情况下以非特权模式运行程序 .

    程序必须提示管理员访问,然后才能以管理员身份运行,并且必须熟悉UAC对话框 . 由于Python脚本不能直接执行,因此没有“以管理员身份运行”上下文菜单选项 .

    可以使用 ctypes.windll.shell32.IsUserAnAdmin() 来检测脚本是否具有管理员访问权限,并使用ShellExecuteEx来检测python.exe上的'runas'动词,并使用sys.argv [0]作为参数来提示UAC对话框(如果需要) .

  • 28

    我刚遇到同样的问题,我的系统是Win7 . 只需在终端上使用命令,如:netstat -na | findstr port,您将看到该端口已被使用 . 因此,如果要在没有此消息的情况下启动服务器,则可以更改未使用的其他端口 .

  • 11

    迈克菲正在阻止它 . 我必须在访问保护规则中允许该程序

    • 打开VirusScan

    • 右键单击Access Protection,然后选择“属性”

    • 点击"Anti-virus Standard Protection"

    • 选择规则"Prevent mass mailing worms from sending mail"并单击编辑

    • 将应用程序添加到要排除的进程列表,然后单击“确定”

    http://www.symantec.com/connect/articles/we-are-unable-send-your-email-caused-mcafee

  • 18

    socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions

    flask 得到了这个:

    意味着您尝试绑定的端口, is already in used by another service or process :在Eclipse / windows上开发的代码中有一个提示:

    if __name__ == "__main__":
         # Check the System Type before to decide to bind
         # If the system is a Linux machine -:) 
         if platform.system() == "Linux":
            app.run(host='0.0.0.0',port=5000, debug=True)
         # If the system is a windows /!\ Change  /!\ the   /!\ Port
         elif platform.system() == "Windows":
            app.run(host='0.0.0.0',port=50000, debug=True)
    
  • -3

    我不得不在Windows防火墙中允许.. \ python27 \ python.exe . 我不需要在WinXP或Win8上执行此操作 .

  • 0

    尝试在不同的端口运行服务器 . 为我工作:

    python manage.py runserver 127.0.0.1:7000
    

    说明:

    如Django文档中所述:

    If you run this script as a user with normal privileges (recommended), you might not have access to start a port on a low port number. Low port numbers are reserved for the superuser (root).

    此服务器使用WSGI_APPLICATION设置指定的WSGI应用程序对象 .

    请勿在 生产环境 设置中使用此服务器 . 它没有经过安全审核或性能测试 . (这就是它将如何保留 . 我们的业务是制作Web框架,而不是Web服务器,因此改进此服务器以便能够处理 生产环境 环境超出了Django的范围 . )

  • 2

    只需在1024以上的端口上运行,下面的任何东西都是特权,它与Linux的交易相同,我在没有任何UAC私有升级的情况下使用5000作为胜利 .

  • 1

    似乎端口80已经在使用中 . 尝试使用系统中任何其他应用程序未使用的其他端口 .

  • 4

    我在Python中找到了解决这个问题的解决方案 .

    转到c:\ python27 \目录并将pyt.exe和tab选中以进行比较,然后选择admin权限选项并应用更改 . 现在,您发出允许创建套接字连接的命令 .

相关问题