0

Python gives the following error:

Traceback (most recent call last):
  File "C:\Python34\Google_Map.py", line 246, in <module>
    main()
  File "C:\Python34\Google_Map.py", line 232, in main
    username = args.username
AttributeError: 'Namespace' object has no attribute 'username'enter code here

I guess I must have passed the argument incorrectly. Please refer to the following code snippet below:

    def main():
# parse arguments
parser = argparse.ArgumentParser(description='InstaRaider')
parser.add_argument('-styledbyafrica', help='Instagram username')
parser.add_argument('-c:\python34\pikshor images\styledbyafrica', help='Where to save the images')
parser.add_argument('-n', '--num-to-download',
                    help='Number of posts to download', type=int)
parser.add_argument('-l', '--log-level', help="Log level", default='info')
args = parser.parse_args()
username = args.username
directory = op.expanduser(args.directory)

raider = InstaRaider(username, directory,
                     num_to_download=args.num_to_download,
                     log_level=args.log_level)

1 Answer 1

2

I'd recommend you check the Argparse Tutorial from Python Docs.

The reason it raises the AttributeError is because you're using different attribute names than the argument names you used in the argparser.

In the error you shared you're trying to get the styledbyafrica argument by using username. That clearly will not work. The directory will also give you problems there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.