0

Title says it all.

Both are PC, both Windows 10, both latest Python (I uninstalled and reinstalled both) and Selenium.

So what am I missing here ? I open a CMD on both PCs and type the same thing :

myscript.py "myurlargument"

It's the very same script that I execute from my Dropbox on one PC on which it works fine, and on the other on which it fails with this error.

The first line of the script :

from selenium import webdriver
import sys

driver = webdriver.Chrome(executable_path="chromedriver")
driver.get(sys.argv[1])

Thanks for your help.

jeremoquai
  • 101
  • 2
  • 10
  • sys.argv is an array of strings passed to it when the program is executed. eg `python file.py https://google.com` - you would run it from cmd.exe like that. – Skarlett Dec 14 '19 at 16:53
  • yes on both pc i open a cmd and type myscriptnamr.py "myargument_whichisanurl" – jeremoquai Dec 14 '19 at 16:55
  • What's the setup for calling a python script without `python name.py arg1 arg2` – hpaulj Dec 14 '19 at 17:03
  • i figured out that if i "forget" the "python" at the beginning of the line it lauches but i have the error, but if i add the "python" at the beginning of the line i don't have it ! on the other PC i don't need the "python" for the script to work – jeremoquai Dec 14 '19 at 17:09
  • Use print(sys.argv) on both systems to see what the difference is. – Jortega Dec 14 '19 at 17:10
  • On `dos` handling `shebang/ #!` requires special setup. One of your machines isn't passing parameters through. – hpaulj Dec 15 '19 at 02:19
  • https://stackoverflow.com/q/11472843/901925 – hpaulj Dec 15 '19 at 02:30

1 Answers1

0

sys.argv[0] represents the script name, and sys.argv[1:] represents the parameters passed. If you know this part and are passing the proper arguments, then try error handling.

Either by putting your code in Try and Except block and putting it to sys.argv[0] or any other values, when it goes index out of range.

My best best would be to debug it, and see what parameters are being passed in both the system and cure your error handling from there, OR by creating a rule or function to use the arguments if provided else use the default Argument.

  • the thing is : it's weird that it works differently ! i cannot figure what is different between the two installations... if one was not launching it might have made sense, but both are launching and not handling the argument the same way – jeremoquai Dec 14 '19 at 20:11
  • I know its weird :p, you can try to run on an image or any other platform for validation sys is supported my all OS. – Lakshya Srivastava Dec 14 '19 at 20:14
  • Also check if you are using any IDE the run configuration is not passing any argument by mistake. – Lakshya Srivastava Dec 14 '19 at 20:15