0

Question related to an earlier asked question (Python - how to read path file/folder from server). I have similar issue- I am using python and used f=open('\\SERVER\share\file.ext', 'r') to open/access folder in a remote server- but its still giving me an error "no such file directory" can you please help me with that.

What I am trying to do is to goto my remote server and read that particular file and upload on my sql database. I am using pyodbc and connection to db is fine, I can query select and even insert individual values in table. But I want to do either a load data local infile query or insert as a loop around my csv file. this is what i have

dsn=name; pw=password
def func(dsn):
    connection = pyodbc.connect(dsn)
    connection.autocommit =True
    cur = connection.cursor()
    csv_data = open (r'\\server-ipaddress\C:\foldername\filename.csv','r')
    for row in csv_data:
            cur.execute("insert into table_name values(?)",row)
Community
  • 1
  • 1
Blue
  • 191
  • 1
  • 1
  • 12
  • The top answer in the question you linked points out at least one issue you have with your `open` command. Try to apply the suggestion given there first, then come back if you are still experiencing issues. Also, please include the full stacktrace of the error you are getting. – Pit Mar 17 '17 at 13:05
  • Yes I tried using f=open('\\\\SERVER\\share\\file.ext', 'r') or two back slashes using raw string. It still doesnt work. I suppose share is the folder name in the example above – Blue Mar 17 '17 at 13:09
  • Then please include the full error you are getting. – Pit Mar 17 '17 at 13:10
  • this is what I have: dsn=name; pw=password def func(dsn): connection = pyodbc.connect(dsn) connection.autocommit =True cur = connection.cursor() csv_data = open (r'\\server-ipaddress\C:\foldername\filename.csv','r') for row in csv_data: cur.execute("insert into table_name values(?)",row) – Blue Mar 17 '17 at 13:19
  • 1
    Please update your question with the new information. That's easier to read there with proper formatting. – languitar Mar 17 '17 at 13:20
  • I have edited- thanks – Blue Mar 17 '17 at 13:32
  • I'm fairly certain that `C:` would be an invalid path segment. Please try to find and open the path in your Explorer first, and insert the correct one into your script. – Pit Mar 17 '17 at 13:37
  • I checked the location/path of the file from properties and it is C:\folder_name- – Blue Mar 17 '17 at 13:49
  • C: is the drive on the server, but the share will have a name that doesn't include C: – DisappointedByUnaccountableMod Mar 17 '17 at 13:54
  • I am sorry barny- but im not sure what you meant. how does this \\server\share work '\\server-ipaddress\C:\foldername\filename.csv' - should I write it like this? '\\server-ipaddress\share\foldername\filename.csv' – Blue Mar 17 '17 at 14:05
  • Can someone please help with my question. I would really appreciate explanation. I need it to done fast and nothing on my end is working. – Blue Mar 18 '17 at 00:20

0 Answers0