服务器python和文件打开错误
我从python开始,根据下面的代码在终端,参数:(in)(out)(ip)(port)(mode)中开发一个输入参数的客户/服务器脚本。在被动模式下,它作为服务器,在主动模式下它起着客户端的作用。 但我不明白提供错误的原因。 有人可以向我解释发生了什么事吗? 谢谢。
码
def Main():
mode = sys.argv[5]
i = 0 # Auxiliar variable in loop
if (mode == "passive"):
port = int(sys.argv[4])
mySocket = socket.socket()
mySocket.bind(('', port)) # Passive connection, for server
mySocket.listen(1)
conn, addr = mySocket.accept()
conn.settimeout(1) # Timeout = 1 segundo
conn.setblocking(0) # Non blockable mode
print("Connection from: " + str(addr))
print("Connected as server")
in_arq = open(sys.argv[1], 'r')
message = in_arq.read() # File to be send
out_arq = open(sys.argv[2], 'w') # File to save data received
elif (mode == "ative"):
host = sys.argv[3]
port = int(sys.argv[4])
mySocket = socket.socket()
mySocket.connect((host, port)) # Active connection, for client
mySocket.settimeout(1) # Timeout = 1 segundo
mySocket.setblocking(0) # Non blockable mode
print("Connected as client")
in_arq = open(sys.argv[1], 'r')
message = in_arq.read() # File to be send
out_arq = open(sys.argv[2], 'w') # File to save data received
else:
print("Wrong arguments.")
if __name__ == '__main__':
Main()
错误:
C: Users AppData Local Programs Python Python35-32 python.exe C: Users Desktop textinput C: Users Desktop textoutput 127.0.0.1 54000 ative
回溯(最近一次通话最后):
File "C:/Users/Desktop/emulator.py", line 221, in <module>
Main()
File "C:/Users/Desktop/emulator.py", line 202, in Main
in_arq = open(sys.argv[1], 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'C:UsersDesktoptextinput'
作为客户连接
链接地址: http://www.djcxy.com/p/9305.html上一篇: server python and file opening error
下一篇: How to pass parameters to python function using argparse?
