Python sys.argv out of range, dont understand why

2024/9/22 9:35:00

I have a script that I've been using for a some time to easily upload files to my server. It has been working great for a long time, but I can't get it to work on my new desktop computer.

The code is simple:

import os.path
import sys
import os
from ftplib import FTPhost = ""
acc = ""
pw = ""
filepath = sys.argv[1]if (not os.path.isfile(filepath)):x = input("ERROR, invalid filepath")exit()filename = os.path.basename(filepath)
file_object = open(filepath, 'rb')ftp = FTP(host)
ftp.login(acc, pw)
ftp.storbinary('STOR ' + filename, file_object)
ftp.quit()file_object.close()

I run it as:

file_uploader.py backup.sql

I get the following error:

Traceback (most recent call last):

File "C:\Users\Admin\Desktop\file_uploader.py", line 12, in

filepath = sys.argv[1]

IndexError: list index out of range

I'm not sure why it's giving me an error that it can't find the first commandline argument even though I passed one to the script.

I am running Windows 7 64-bit with Python 2.7.2

Thanks

Answer

Your .py association in the registry is incorrect. It's missing %* at the end.

https://en.xdnf.cn/q/71961.html

Related Q&A

Error calling BashOperator: Bash command failed

Here are my dag file and BashOperator task:my_dag = { dag_id = my_dag, start_date = datetime(year=2017, month=3, day=28), schedule_interval=01***, }my_bash_task = BashOperator( task_id="my_bash_t…

Match unescaped quotes in quoted csv

Ive looked at several of the Stack Overflow posts with similar titles, and none of the accepted answers have done the trick for me.I have a CSV file where each "cell" of data is delimited by …

Creating RDF file using csv file as input

I need to convert a csv file to rdf with rdflib, I already have the code that reads the csv but I do not know how to convert it to rdf.I have the following code:import csv from rdflib.graph import Grap…

Explicit vertex position in python graph-tool

I am using python graph-tool. To draw graphs, it uses graph_draw function. I want to send vertex positions explicitly to dot engine. It turns out that I can pass a property map named pos. I tried defin…

Add jar to pyspark when using notebook

Im trying the mongodb hadoop integration with spark but cant figure out how to make the jars accessible to an IPython notebook.Here what Im trying to do:# set up parameters for reading from MongoDB via…

how do I create a python list with a negative index

Im new to python and need to create a list with a negative index but have not been successful so far.Im using this code:a = [] for i in xrange( -20, 0, -1 ):a[i] = -(i)log.info(a[{i}]={v}.format(i=i, v…

Select subset of Data Frame rows based on a list in Pandas

I have a data frame df1 and list x:In [22] : import pandas as pd In [23]: df1 = pd.DataFrame({C: range(5), "B":range(10,20,2), "A":list(abcde)}) In [24]: df1 Out[24]:A B C 0 a …

convert csv to json (nested objects)

I am new to python, and I am having to convert a csv file to json in following format:CSV File :firstname, lastname, email, customerid, dateadded, customerstatus john, doe, [email protected], 124,26/11…

How can I read exactly one response chunk with pythons http.client?

Using http.client in Python 3.3+ (or any other builtin python HTTP client library), how can I read a chunked HTTP response exactly one HTTP chunk at a time?Im extending an existing test fixture (writt…

ValueError: cannot reindex from a duplicate axis in groupby Pandas

My dataframe looks like this:SKU # GRP CATG PRD 0 54995 9404000 4040 99999 1 54999 9404000 4040 99999 2 55037 9404000 4040 1556894 3 55148 9404000 4040 1556894 4 55254 94…