4

The idea is to download a zipped file from a website and unzip it using FME 2011. I have attached a screenshot of FME workbench which is not working.

FME Workbench

1
  • 1
    It may be helpful if you posted the unobscured error from the log.
    – Raven
    Commented Sep 2, 2011 at 18:30

2 Answers 2

1

Your code seems incorrect. Try:

import pyfme, os, zipfile
z = zipfile.ZipFile("GoTransitDL.zip")
z.extractall()

And just as a warning (from API docs):

Warning Never extract archives from untrusted sources without prior inspection. It is possible that files are created outside of path, e.g. members that have absolute filenames starting with "/" or filenames with two dots "..".

The zip file can be made to extract files to anywhere on your hard drive, and z.extractall() will oblige. Very dangerous if you don't know the source.

3
  • Thanks Sasa. I changed the code as you suggested but it gave me the same error. I am wondering if the parameters that I set are creating errors. Also is there a safer way to download and unzip files from a website using FME?
    – Sam
    Commented Aug 25, 2011 at 18:37
  • Tend to download the files first and have the virus scanner run through them first before extracting - would be good if FME could run the virus scanner as part of the process.
    – Mapperz
    Commented Aug 25, 2011 at 20:27
  • Sam, make sure your import is using the correct case - your code imports ZipFile rather than zipfile. Based on what I can see of the FME log it appears a module isn't being found.
    – Raven
    Commented Sep 2, 2011 at 18:33
0

I just did the exact same thing. You should check the documentation on the PythonCaller. You need to create a function or class as described in the help. Use a function to process a single feature, as in this case.

Example:

from zipfile import ZipFile

def fmeUnzip(fmeFeature):
    zipFile = fmeFeature.getAttribute("_ZIPFILE_NAME")
    outDir = fmeFeature.getAttribute("_OUTPUT_DIR")
    unzip(zipFile, outDir)

def unzip(zipFile, outDir):
    z = ZipFile(zipFile)
    z.extractall(outDir)

In the PythonCaller parameters, set 'Symbol to use' to fmeUnzip and copy the code to the source code parameter. You can alternatively save it in a .py file, see the PythonCaller help for how to do this.

Note: _ZIPFILE_NAME and _OUTPUT_DIR are attributes created by ParameterFetcher transformers, which create attributes based on the values of workspace parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.