Hi All,
I am trying to access data from SFTP and I have written a code in python tool and it works perfectly from alteryx designer. When I try to push it to server, I get the error " Object reference not set to an instance of an object" Then I realised I am reading my private key from local machine and so I pushed it to online and used the link to read the data. But still i get the same error.
I suspect the error could be due to pandas as I am getting the file from SFTP and using pandas to convert into data frame locally and this could be the reason for the error. Is there anyway I can get rid of this error? Please advise.
Below is the code for your reference.
Thank you.
import pysftp
import re
sftphost='xxxxxxx'
sftpport=22
uname='xxxxx'
privatekeyfilepath=r'xxxx'
cnOpts=pysftp.CnOpts()
cnOpts.hostkeys=None
with pysftp.Connection(host=sftphost,port=sftpport,username=uname,private_key=privatekeyfilepath, cnopts=cnOpts) as srv:
print("connection successful")
data = srv.listdir()
srv.get("Test_Report1.csv")
import pandas as pd
df = pd.read_csv('Test_Report1.csv',encoding='latin-1')
df2=pd.DataFrame(data=df)
Alteryx.write(df2,1)