'Python For Loop Issues in SmbConnection
I'm trying to move excel files from a network folder to Airflow DAG folder. I am using pysmb and have tested my logic and DAG when connected to a particular file in the network folder, but when i am using for loop to go through the excel files, I am getting errors which don't make sense.
Exception:
unsupported operand type(s) for &: 'int' and 'str'
This is what I am doing.
base_dir = os.path.dirname(os.path.realpath(__file__))
sql_dir = os.path.join(base_dir, 'sql')
staging_dir = os.path.join(base_dir, 'excel_dump')
def pull_file_from_network_share(**kwargs):
conn = SambaHook.get_connection("CPA")
pw = conn.get_password()
print(pw)
share_name = "cpa"
user_name = "[email protected]"
local_machine_name = "lap10" # arbitrary
server_machine_name = "boss2b.xyz.com" # MUST match correctly
server_IP = "107.21.03.78" # as must this
# create and establish connection
conn = SMBConnection(user_name, pw, local_machine_name, server_machine_name, use_ntlm_v2 = True)
conn.connect(server_IP, 139)
fileList = conn.listPath(share_name,"/SPTS/TaskScheduler/SPE/XYZ/XYZT_RPA/PQR_EU/","*.xlsx")
# Iterate over the list of filepaths & move each file.
for filePath in fileList:
file_obj = tempfile.NamedTemporaryFile(delete=False)
csv=os.path.join(staging_dir, filePath)
file_attributes, filesize = conn.retrieveFile(share_name, os.path.join(fileList, filePath), file_obj)
file_obj.close()
shutil.copy(file_obj.name, csv)
os.remove(file_obj.name)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
