elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [Python 3] TypeError: an integer is required (got type str)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Python 3] TypeError: an integer is required (got type str)  (Leído 3,394 veces)
n1sen

Desconectado Desconectado

Mensajes: 122



Ver Perfil
[Python 3] TypeError: an integer is required (got type str)
« en: 16 Noviembre 2017, 01:48 am »

Tengo un error que me esta sacando de quisio, hace un dia funcionaba perfecto, pero no se que paso, este es el error que me tira:

Código:
Traceback (most recent call last):
  File "cmd_main.py", line 49, in <module>
    maincmd()
  File "cmd_main.py", line 28, in maincmd
    date(cmd_input)
TypeError: an integer is required (got type str)
No se que rompi, solo dejo de funcionar derrepente...
Aca el codigo del cmd_main.py
Código
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import platform
  5. import sys
  6. from boot import *
  7. from commands import *
  8. from panic import *
  9. from dir_cmd import *
  10. from date_cmd import *
  11. from mkdir import *
  12.  
  13. global machine_name
  14. machine_name = platform.node()
  15.  
  16. def maincmd():
  17.    while True:
  18.        cmd_input = input("[%s]$~ " % machine_name)
  19.  
  20.        if "println" in cmd_input:
  21.            println(cmd_input)
  22.  
  23.        elif "clear" in cmd_input:
  24.            clear()
  25.            maincmd()
  26.  
  27.        elif "date" in cmd_input:
  28.            date(cmd_input)
  29.  
  30.        elif "machine_info" in cmd_input:
  31.            machine_info()
  32.  
  33.        elif "panic" in cmd_input:
  34.            panic("ran_out_mem")
  35.  
  36.        elif "dr" in cmd_input:
  37.            dr(cmd_input)
  38.  
  39.        elif "mkdir" in cmd_input:
  40.            mkdir(cmd_input)
  41.  
  42.        elif "commd_list" in cmd_input:
  43.            commd_list(cmd_input)
  44.  
  45.        else:
  46.            invalidCommand(cmd_input)
  47.  
  48. login()
  49. maincmd()
  50.  
y el codigo del date_cmd.py:
Código
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import calendar
  5. from datetime import datetime, date, time, timedelta
  6. import time
  7.  
  8. def date_cmd(args):
  9.    date_now = datetime.now()
  10.    time_epoch = time.time()
  11.  
  12.    try:
  13.        cmd_input = args.split(' ')
  14.        argument = cmd_input[1]
  15.  
  16.        if argument == "-e":    
  17.            print("Epoch time: %s" % time_epoch)
  18.  
  19.        elif argument == "-12":
  20.            date_format_12 = "%d/%m/%Y %I:%m %p"
  21.            date_12 = date_now.strftime(date_format_12)
  22.  
  23.            print("Date (12 hours format): %s" % date_12)
  24.  
  25.        elif argument == "-24":
  26.            date_format_24 = "%d/%m/%Y %H:%M:%S"
  27.            date_24 = date_now.strftime(date_format_24)
  28.  
  29.            print("Date (24 hours format): %s" % date_24)
  30.  
  31.        elif argument == "-h":
  32.            print(help_arg)
  33.  
  34.        else:
  35.            print("\033[1;36m"+'invalid argument for "date" command')
  36.            help_arg()
  37.  
  38.    except IndexError:
  39.        help_arg()
  40.    except TypeError:
  41.        help_arg()
  42.  
  43.    finally:
  44.        print("\033[;37m")
  45.  
  46. def help_arg():
  47.    print("""Date command made by n1sendev.
  48. &#9556;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9559;
  49. &#9553; \"date\" command help:   &#9553;
  50. &#9568;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9577;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9559;
  51. &#9553;Arguments (options):                                  &#9553;
  52. &#9553;                                                      &#9553;
  53. &#9553;-12 = Display the date and the hour in 12-hour format.&#9553;
  54. &#9553;-24 = Display the date and the hour in 24-hour format.&#9553;
  55. &#9553;-e = Display the date and time in epoch format.       &#9553;
  56. &#9553;-h = Display this help menu.                          &#9553;
  57. &#9562;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9565;
  58.               """)
  59.  
Saludos
PD: Esas palabras raras que empiezan con & alparecer es un bug del foro, ya que enrealidad son carcacteres para dibujar cajas, estan en ASCII


« Última modificación: 16 Noviembre 2017, 01:55 am por n1sen » En línea

null
n1sen

Desconectado Desconectado

Mensajes: 122



Ver Perfil
Re: [Python 3] TypeError: an integer is required (got type str)
« Respuesta #1 en: 16 Noviembre 2017, 01:54 am »

Vale, error arreglado, el tan idiota de mi puso date() envez de date_cmd()...
Merezco un premio a la idiotez


En línea

null
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
lvalue required as left operand of assignment
Programación C/C++
uhuru 7 10,943 Último mensaje 4 Mayo 2010, 01:39 am
por Og.
Error en C: (Ivalue required as left...)
Programación C/C++
Constantinoplero 3 7,964 Último mensaje 13 Noviembre 2011, 14:31 pm
por DickGumshoe
(Python) TypeError: can't multiply sequence by non-int of type 'str'
Scripting
Linton 9 6,770 Último mensaje 17 Febrero 2013, 09:36 am
por Linton
required html5 y onsubmit...
Desarrollo Web
basickdagger 1 1,794 Último mensaje 9 Febrero 2014, 13:28 pm
por #!drvy
TypeError: 'str' object cannot be interpreted as an integer(python)
Scripting
El mas antiguo 4 2,883 Último mensaje 18 Noviembre 2022, 00:05 am
por El mas antiguo
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines