【发布时间】:2016-01-06 23:38:02
【问题描述】:
我正在从事计算机网络的编程练习:Kurose 和 Ross 的自顶向下方法(第 6 版)
当我运行服务器代码并在浏览器中键入 localhost:1234/www.facebook.com 时,我遇到了 List Index Out of Range 错误。
错误: 收到来自: ('127.0.0.1', 15376) 的连接
消息: 回溯(最近一次通话最后): 文件“Manu.py”,第 17 行,打印 message.split()[1]
IndexError: 列表索引超出范围
代码:
from socket import socket
import sys
if len(sys.argv) <= 1:
print('Usage: "python ProxyServer.py server_ip\n'
'server_ip: It is the IP Address of the Proxy Server')
sys.exit(2)
# Create a server socket, bind it to a port and start listening
tcpSerPort = 1234
tcpSerSock = socket(AF_INET, SOCK_STREAM)
# Prepare a server socket
tcpSerSock.bind(('', tcpSerPort))
tcpSerSock.listen(5)
while True:
# Start receiving data from the client
print 'Ready to serve...'
tcpCliSock, addr = tcpSerSock.accept()
print 'Received a connection from: ', addr
message = tcpCliSock.recv(1024)
# Extract the filename from the given message
print message.split()[1]
filename = message.split()[1].partition("/")[2]
fileExist = "false"
filetouse = "/" + filename
【问题讨论】:
标签: python proxy network-programming