AttributeError: 'Namespace' object has no attribute 'brokeName' - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: AttributeError: 'Namespace' object has no attribute 'brokeName' (/thread-3420.html) |
AttributeError: 'Namespace' object has no attribute 'brokeName' - kikilalongue - May-22-2017 People! Greetings from Suriname!! I try to get this up. What's the way to run this up? The piece of code : #!/usr/bin/python # -*- coding: utf-8 -*- import argparse,sys,requests #parser parser = argparse.ArgumentParser(description='MOM.') #diff arguments parser.add_argument('-q', '--queuenum', type=str, dest='SantQue', action='store', help='un numero de queue') parser.add_argument('-b', '--brknum',type=str, dest='brokeName', action='store', default='brk01', help='un num de broker') args = parser.parse_args() print (args) queue=requests.get('h..p://localhost:8161/api/...') brokk=requests.get('h..p://localhost:8161/api/...brokerName={}'.format(args.brokeName),auth=('...')) if args.SantQue: print (queue.json()) else: print ("dong error") #print (queue.json()) #print (queue) #print (mountain.json()) #print (mountain)Sorry for my incompetence RE: AttributeError: 'Namespace' object has no attribute 'brokeName' - buran - May-22-2017 please, post full Traceback in error tags. RE: AttributeError: 'Namespace' object has no attribute 'brokeName' - kikilalongue - May-22-2017 Namespace(SantBrK='brk01', SantQue='P35') Traceback (most recent call last): File "jSonTest02.py", line 18, in <module> brokk=requests.get('http://localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName={}'.format(args.SantBrk),auth=('admin', 'admin')) AttributeError: 'Namespace' object has no attribute 'SantBrk' RE: AttributeError: 'Namespace' object has no attribute 'brokeName' - buran - May-22-2017 That Traceback is not error produced by running the code in the original post. Anyway, there is no SantBrk defined in the above code. import argparse parser = argparse.ArgumentParser(description='MOM.') parser.add_argument('-b', '--brknum',type=str, dest='brokeName', action='store', default='brk01', help='un num de broker') args = parser.parse_args() print(args.brokeName)running without any command line arguments return the default value Now I noticed that in the Namespace output you have SantBrK with capital K
RE: AttributeError: 'Namespace' object has no attribute 'brokeName' - kikilalongue - May-22-2017 You ah chief !!!! I was on this from weeks !!! I just changed the variables to recognize them more easily!! the namespace was the problem!! thank you buran. |