I have created a fme workbench. It has creator transformer, python caller and S3 Uploader. The purpose of the workbench is to created a pdf (python script does it) and to upload that pdf to S3.
Our FME is 2019.2. I am using custom python3 installation.
If I just run creator and python caller, all works fine. If I disable python caller, and run creator and uploader, all works fine as well. If all parts are connected, I am getting an error:
Python Exception <ImportError>: cannot import name 'ssl' from 'urllib3.util.ssl_' (D:\Program Files\FME2019.2.3\python\urllib3\util\ssl_.py)
PythonFactory failed to load python symbol `fmepy_amazons3.connector.S3Connector'
Factory proxy not initialized
S3Connector_CALLER (PythonFactory): PythonFactory failed to process feature
A fatal error has occurred. Check the logfile above for details
Bridge failed to output feature on tag `PYOUTPUT'
PythonCaller (PythonFactory): PythonFactory failed to process feature
In all cases, python script creates output pdf and I can see that it runs to the end (I have print statements).
# Template Function interface:
# When using this function, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter
def processFeature(feature):
file_location = FME_MacroValues['pdf']
folder = r'https://publiccontent-gis-psba-qld-gov-au.s3.amazonaws.com/content/PDFs/'
file_name = file_location.rsplit('\\', 1)[1]
file_path = file_location.rsplit('\\', 1)[0]
file_link = folder + file_name
aws_link = file_link.replace(" ", "%20") # for qr coding
aws_folder = FME_MacroValues['S3_Path'] #'content/PDFs/' # for S3 upload
aws_bucket = FME_MacroValues['S3Bucket'] #'publiccontent-gis-psba-qld-gov-au'
temp_path = 'D:\\Temp\\'
output_pdf = os.path.join(temp_path, file_name) # output pdf for final document
print ("file path done")
# create qr code image
qr = pyqrcode.create(aws_link)
qr.svg(temp_path +'qr_svg.svg', scale=2, background="white", module_color="#000000")
# convert svg to pdf
drawing = svg2rlg(temp_path+'qr_svg.svg')
renderPDF.drawToFile(drawing, temp_path+'qr_pdf.pdf')
print ("this part done")
input1 = PdfFileReader(open(file_location, 'rb'), strict=False)
map_size = input1.getPage(0).mediaBox
input2 = PdfFileReader(open(temp_path +'qr_pdf.pdf', 'rb'), strict=False)
qrcode_size = input2.getPage(0).mediaBox
# merge pdf map and qr code pdf
# function for merging two pdfs
def create_qrCode(input_pdf, qr_code, output_pdf):
qr_obj = PdfFileReader(qr_code, strict=False)
qr_page = qr_obj.getPage(0)
pdf_reader = PdfFileReader(input_pdf, strict=False)
pdf_writer = PdfFileWriter()
# QrCode all the pages
for page in range(pdf_reader.getNumPages()):
page = pdf_reader.getPage(page)
page.mergePage(qr_page)
pdf_writer.addPage(page)
with open(output_pdf, 'wb') as out:
pdf_writer.write(out)
create_qrCode(file_location, temp_path +'qr_pdf.pdf', output_pdf)
print("qr code file create")
feature.setAttribute("file_out", output_pdf)
print("script is done - ")