Я пытаюсь получить доступ к несуществующему типу файла с помощью http://myipaddr: 50997 / notExisted. html, но получаю следующую ошибку. Может кто-нибудь объяснить мне?
from socket import *
serverPort = 50997
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(("", serverPort))
serverSocket.listen(1)
# Server should be up and running and listening to the incoming connections
while True:
print ("Ready to serve...")
# Set up a new connection from the client
connectionSocket, addr = serverSocket.accept()
try:
# Receives the request message from the client
message = connectionSocket.recv(1024)
print ("Message is: "), message
filename = message.split()[1]
print ("File name is: "), filename
f = open(filename[1:])
outputdata = f.read()
connectionSocket.send("HTTP/1.1 200 OK\r\n\r\n")
for i in range(0, len(outputdata)):
connectionSocket.send(outputdata[i])
connectionSocket.send("\r\n")
# Close the client connection socket
connectionSocket.close()
except IOError:
# Send HTTP response message for file not found
connectionSocket.send("HTTP/1.1 404 Not Found\r\n\r\n")
connectionSocket.send("<html><head></head><body><h1>404 Not Found</h1></body></html>\r\n")
# Close the client connection socket
connectionSocket.close()
serverSocket.close()
Ошибка, которую я получаю.
connectionSocket.send(bytes("HTTP/1.1 404 Not Found\r\n\r\n","UTF-8"))
TypeError: str() takes at most 1 argument (2 given)
У меня эта ошибка возникает при попытке удалить bytes ();
Traceback (most recent call last):
File "tcpServer.py", line 26, in <module>
connectionSocket.send("HTTP/1.1 404 Not Found\r\n\r\n","UTF-8")
TypeError: an integer is required