[SOLUCIONADO] Duda python

Iniciado por jhou_026, Octubre 19, 2019, 11:23:45 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Octubre 19, 2019, 11:23:45 PM Ultima modificación: Octubre 20, 2019, 03:13:23 AM por Gabriela
Buenas buenasss! tengo una duda si alguien me ayuda le agradecería uso python 2.7

Código: text
#!/usr/bin/env python
#_*_ coding: utf8 _*_

import requests
import argparse

parser = argparse.ArgumentParser(description="Detector de cabeceras")
parser.add_argument("-t","--targer",help="Objetivo") #añade arguento
parser = parser.parse_args() #terminacion de definir argumentos a mostrar


def main():
if parser.target:
try:
url = requests.get(url=parser.target)
cabeceras = dict(url.headers)
for x in cabeceras:
print(x + " : " + cabeceras[x])
except:
print("No me pude conectar")
else:
print("No hay Objetivo")

if __name__ == "__main__":
main()


al ejecutarlo >>> python You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login -t You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

me sale este error:

Código: text
Traceback (most recent call last):
  File "cabeceras.py", line 25, in <module>
    main()
  File "cabeceras.py", line 13, in main
    if parser.target:
AttributeError: 'Namespace' object has no attribute 'target'


agradezco de antemano la ayuda  :)

Octubre 19, 2019, 11:54:22 PM #1 Ultima modificación: Octubre 20, 2019, 07:14:17 AM por DtxdF
@You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Código: python

parser.add_argument("-t","--targer",help="Objetivo") #añade arguento


Escribiste "targer" en vez de "target", qué supongo yo, es como lo quieres llamar, debido a qué, lo "llamas" en:

Código: python

if parser.target:


Por lo tanto. Una vez aclarado. Debes colocarlo de esta manera:
Código: python

parser.add_argument("-t","--target",help="Objetivo") #añade arguento

PGP :: <D82F366940155CB043147178C4E075FC4403BDDC>

~ DtxdF

jajajajaj no mamesssss gracias enserio! que cosa tan simple como ser detallista... puedes creer que lo lei como 10 veces y se me paso te agradezco  ;)