Python does not state the line of code that an error refers to

痴心易碎 提交于 2019-12-02 12:21:17

That's not a Python exception message. That's command line help output.

The output is generated by the argparse module, configured here:

def main():
    # parse arguments
    parser = argparse.ArgumentParser(description='InstaRaider')
    parser.add_argument('username', help='Instagram username')
    parser.add_argument('directory', 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()

The moment parser.parse_args() is called your command line arguments are parsed to match the above configuration.

Specifically, the username and directory positional arguments are required:

parser.add_argument('username', help='Instagram username')
parser.add_argument('directory', help='Where to save the images')

You'll need to specify these on the command line when you run the script:

Google_Map.py some_instagram_username /path/to/directory/to/save/images

The other command line options are optional and start with - or --.

If you can't run this from a console or terminal command line, you could pass in the options to the parser directly:

def main(argv=None):
    # parse arguments
    parser = argparse.ArgumentParser(description='InstaRaider')
    parser.add_argument('username', help='Instagram username')
    parser.add_argument('directory', 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(argv)
    # ....

main(['some_instagram_username', '/path/to/directory/to/save/images'])

Now the arguments are passed in via the argv optional function parameter, as a list.

However, rather than have main() parse arguments, you could just use the InstaRaider() class directly:

raider = InstaRaider('some_instagram_username', '/path/to/directory/to/save/images')
raider.download_photos()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!