相关疑难解决方法(0)

获取Errno 9:python套接字中的文件描述符错误

我的代码是这样的:

while 1:
    # Determine whether the server is up or down
    try:
        s.connect((mcip, port))
        s.send(magic)
        data = s.recv(1024)
        s.close()
        print data
    except Exception, e:
        print e
    sleep(60)
Run Code Online (Sandbox Code Playgroud)

它在第一次运行时工作正常,但每次都给我Errno 9.我究竟做错了什么?

顺便说一句,

mcip = "mau5ville.com"
port = 25565
magic = "\xFE"
Run Code Online (Sandbox Code Playgroud)

python sockets

26
推荐指数
2
解决办法
7万
查看次数

OSError:[Errno 9] Python 3中的错误文件描述符

我是一个初级/中级程序员,目前正在尝试使用Python 3编写一个简单的Web服务器。但是,每当我运行该模块时,都会出现OSError:[Errno 9]错误的文件描述符。我搜寻了互联网以寻找答案,但我似乎无法自己解决这个问题。这是代码和回溯:

#import socket module

from socket import *

serverSocket=socket(AF_INET,SOCK_STREAM)

#Prepare a server socket

serverSocket.bind(('IP address', 8000))
serverSocket.listen(1)

while True:
#Establish the connection

 print('Ready to serve...')

 (connectionSocket, addr) = serverSocket.accept()

 print ('connected from',addr)

 try:


      message=connectionSocket.recv(1024)
      filename=message.split()[1]
      print (filename)

      filename=message.split()[1]

      f=open(filename[1:])

      outputdata=f.read()

 #Send one HTTP header line into socket

      connectionSocket.send('HTTP/1.1 200 OK')

 #Send the content of the requested file to the client

      for i in range(0, len(outputdata)):
           connectionSocket.send(outputdata[i])
           connectionSocket.close()
 except IOError as err:
      print ('IO error')


           #Send response message for …
Run Code Online (Sandbox Code Playgroud)

python sockets webserver

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×2

sockets ×2

webserver ×1