简体   繁体   English

列表索引超出范围 indexerror

[英]list index out of range indexerror

I have an error with the range of the list, I would like to know your opinion, try to change values in ARGV but anyway I have error executing我的列表范围有误,我想知道您的意见,尝试更改 ARGV 中的值,但无论如何我执行时出错

Hola tengo un error de python que me dice que mi arreglo esta fuera de rango, quisiera saber su opinion, saludos Hola tengo un error de python que me dice que mi arreglo esta fuera de rango, quisiera saber su opinion, saludos

from socket import *
from sys import *
import time


if (len(argv) > 2):
print("Error en argumentos")
exit(1)

HOST = '127.0.0.1'
PUERTO = int(argv[1])

s = socket(AF_INET, SOCK_STREAM)
s.bind((HOST, PUERTO))
s.listen(1)

while True:                     
(conn, addr) = s.accept() 
datos = conn.recv(1024)
if not datos: break      
datos.decode()
tservidor = time.time()
respuesta="*"
print ("Hora del servidor: %f " %  tservidor) 
conn.send(respuesta.encode()) 
conn.close()             


ERROR : 

  PUERTO = int(argv[1])
 IndexError: list index out of range

intente cambiando valores en argv pero de todos modos me dice que el lugar es nulo, intente cambiando valores en argv pero de todos modos me dice que el lugar es nulo,

I have an error with the range of the list, I would like to know your opinion, try to change values in ARGV but anyway I have error executing我的列表范围有误,我想知道您的意见,尝试更改 ARGV 中的值,但无论如何我执行时出错

My command to execute the script is "servidor.py 5000"我执行脚本的命令是“servidor.py 5000”

Your error is because you never passed an argument to the command-line.您的错误是因为您从未将参数传递给命令行。 argv[1] means nothing as a result. argv[1]结果没有任何意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM