image_url = sys.argv[1] IndexError: list index out of range

后端 未结 1 521
悲哀的现实
悲哀的现实 2021-01-27 14:41

I am having an issue with the following section of Python code:

import sys  
import requests  
import firebase_admin  
from firebase_admin import credentials  
f         


        
1条回答
  •  后悔当初
    2021-01-27 15:18

    sys.argv list is populated from the command line arguments passed to the script, so in case none are provided it's expected to get an error like

    Traceback (most recent call last):
    File "demo4.py", line 6, in 
    image_url = sys.argv[1]
    IndexError: list index out of range
    

    An easy repro is to put

    import sys
    print(sys.argv[1])
    

    in demo.py and run it using python demo.py. You'll get the output

    $ python demo.py
    Traceback (most recent call last):
      File "demo.py", line 2, in 
        print(sys.argv[1])
    IndexError: list index out of range
    

    but if you pass an argument to it using python demo.py foo you'll get the desired output:

    $ python demo.py foo
    foo
    

    Specifically for your example, looks like when calling demo4.py script you're not passing image url command line argument. You can pass it using python demo4.py .

    0 讨论(0)
提交回复
热议问题