Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Download ZIP file error zip.txt empty

MinhTa
7 - Meteor

Hello,

 

I am trying to download zip file and output them into a folder. I applied workflow called DownloadAndExtractZips(solution in one of other community post on how to download zip file) into my workflow but the process have an error. It seems like my zip.txt file (which includes all the name of the files inside the zip folder) is empty. The workflow is not fetching the names properly. The zip file is password protected so I believe this may have caused the issue. What are the commands I need to add to be able to get the file names?

 

Thank you.

 

MinhTa_1-1635972537220.png

MinhTa_0-1635973469603.png

 

MinhTa_2-1635972818727.png

 

 

23 REPLIES 23
Maskell_Rascal
13 - Pulsar

Hi @MinhTa - Can you confirm which of the files is password protected?

  • base64
  • zip file
  • files in the zip file

The error you provided appears that the CSV file inside the zip file requires a password, but want to confirm before we think about next steps. 

MinhTa
7 - Meteor

@Maskell_Rascal I just confirmed this with higher up and only the zip is password protected. Files inside the zip are not.

Maskell_Rascal
13 - Pulsar

Hi @MinhTa 

 

Lets try this again! 😀

 

I added a text input that is reading into Python with a password. This password is then fed into the zip file when opening/extracting. You will need to update the text input file with your password to make this work. You could also feed in a file stored locally on your computer, so the password isn't saved in the actual workflow. Just make sure that the file has a column labeled "Password". 

 

Maskell_Rascal_0-1636134422664.png

 

from ayx import Alteryx
import pandas as pd
import zipfile
import glob
import base64
filepath = Alteryx.read("#1")
file = filepath['File'].iloc[0]
file2 = filepath['FileDecoded'].iloc[0]
pswd = bytes(Alteryx.read("#2")['Password'].iloc[0],'utf-8')

with open(file, 'rb') as file_input, open(file2, 'wb') as file_output:
    base64.decode(file_input, file_output)

for zip_file in glob.glob(file2):
    zf = zipfile.ZipFile(zip_file)
    dfs = [pd.read_csv(zf.open(f, mode='r', pwd=pswd), header=None, sep=",") for f in zf.namelist()]
    df = pd.concat(dfs,ignore_index=True)
    print(df)
    
Alteryx.write(df,1)

 

Let me know if this one works for you. 

 

Phil

MinhTa
7 - Meteor

Hello @Maskell_Rascal,

 

Thank you very much, I was able to extract the file successfully (saw the data appear in the output section). There is 1 question I have left is how can I distinguish where the data came from (from which file)? I want to output them into excel or csv file so I need to way to distinguish them when output. The zip file I have only 1 file inside but lets say I have more than 1 then how can I solve this.

 

Thank you, very grateful for your help.

Labels