Damian Damian - 1 year ago 78
Python Question

Opening file from a Fileshare-system with python

im trying to open a file from a Filesharing-System of our company. Here is the Code of the script:

import sys
import xlrd
from tkinter import *
import pandas as pd
import time
from os import *

#hvl_file_path = filedialog.askopenfilename()
save_path = filedialog.asksaveasfilename(initialdir="C:/", defaultextension=".xlsx")

t1 = time.clock()
hvl = pd.read_csv('\\Q4DEE1SYVFS.ffm.t-systems.com\pasm$\Berichte_SQL\HVL.csv', sep='|', encoding='latin1', low_memory=False)
hvl.to_excel(save_path, index=False)
t2 = time.clock()
t_ges = t2 - t1

You can see the file_path is: \Q4DEE1SYVFS.ffm.t-systems.com\pasm$\Berichte_SQL\HVL.csv

When i start the script i get the following error:

Traceback (most recent call last):
File "C:/Users/A52113242/Desktop/PROJEKTE/[INPROGRESS] AUSWERTUNG COIN + HVL/hvl_convert.py", line 13, in <module>
hvl = pd.read_csv('Q4DEE1SYVFS.ffm.t-systems.com\pasm$\Berichte_SQL\HVL.csv', sep='|', encoding='latin1', low_memory=False)
File "C:\Users\A52113242\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 474, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\A52113242\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 250, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\A52113242\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 566, in __init__
File "C:\Users\A52113242\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 705, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\Users\A52113242\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 1072, in __init__
self._reader = _parser.TextReader(src, **kwds)
File "pandas\parser.pyx", line 350, in pandas.parser.TextReader.__cinit__ (pandas\parser.c:3187)
File "pandas\parser.pyx", line 594, in pandas.parser.TextReader._setup_parser_source (pandas\parser.c:5930)
OSError: File b'Q4DEE1SYVFS.ffm.t-systems.com\\pasm$\\Berichte_SQL\\HVL.csv' does not exist

So my question is if there is a problem with the path or its a point of missing permissions. Do you have any ideas?

Thank you!


Now i tried to open the file:

f = open('\\Q4DEE1SYVFS.ffm.t-systems.com\pasm$\RFM\Berichte_SQL\HVL.csv','w')

After trying to open the file with open i get this error:

Traceback (most recent call last):
File "C:/Users/A52113242/Desktop/PROJEKTE/[INPROGRESS] AUSWERTUNG COIN + HVL/hvl_convert.py", line 13, in <module>
f = open('\\Q4DEE1SYVFS.ffm.t-systems.com\pasm$\Berichte_SQL\HVL.csv','w')
TypeError: an integer is required (got type str)

Answer Source

When dealing with UNC strings or Windows strings in general it is better to declare constant strings with the r (raw) prefix:

pd.read_csv(r'\\Q4DEE1SYVFS.ffm ...')

not doing that result in some chars to be interpreted:



foo est   (tabulation has been inserted)

Same goes for many lowercase chars (`\t,\n,\v,\b,\x ...).

Double antislashes means "escape the antislash" and is converted a single backslash.




thus your path is incorrect.

But there's more here. You shouldn't get expected int found str errors. So I found out the problem in one of your comments: there are some invisible chars causing trouble. I pasted the path from your comments in pyscripter and assigned it to a variable and go this:

>>> z=r"\\Q4DEE1SYVFS.ffm.t-systems.com\pasm$\Berichte_SQL\HVL‌​.csv"
>>> z

Just rewrite the last part of your string and it will work.

PS: notepad++ was unable to see the weird chars. I heard that SciTe had a tendency to let those pass too. Pyscripter sees them.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download