I have this function which returns the path to the file I need to read
JavaScript
x
7
1
def specie_to_file(specie):
2
switcher = {
3
'human': 'sftp://eliran@SERVER/PATH/TO/FILE1',
4
'mouse': 'sftp://eliran@SERVER/PATH/TO/FILE2'
5
}
6
return switcher.get(specie, None)
7
Later on, I am trying to open the file
JavaScript
1
2
1
database = pd.read_csv(db_file, sep='t')
2
db_file
holds one of the paths above.
When I execute the script I get this error:
JavaScript
1
8
1
Traceback (most recent call last):
2
.
3
.
4
.
5
File "gene_converter.py", line 111, in converter
6
database = pd.read_csv(open(db_file), sep='t')
7
FileNotFoundError: [Errno 2] No such file or directory: 'sftp://eliran@SERVER/PATH/TO/FILE1'
8
I have checked the files names and the paths they all exist and in the right location.
I have tried the following and got the same traceback:
JavaScript
1
2
1
database = pd.read_csv(Path(db_file), sep='t')
2
JavaScript
1
2
1
database = pd.read_csv(open(db_file,'r'), sep='t')
2
JavaScript
1
2
1
database = pd.read_csv(open(db_file,'r').read(), sep='t')
2
Advertisement
Answer
Your file is on FTP server.
Use paramiko in order to read it.
JavaScript
1
3
1
with sftp.open("sftp://eliran@SERVER/PATH/TO/FILE1") as f:
2
pd.read_csv(f)
3