Getting NotImplementedError when trying to send a file to a generic worker

I am trying to send an uploaded file to the worker, but I keep getting the following error:

2023-04-28 08:59:53.969 ERROR : Exception is raised
Traceback (most recent call last):
File “viktor_connector\connector.pyx”, line 295, in connector.Job.execute
File “viktor\core.pyx”, line 1920, in viktor.core._handle_job
File “viktor\core.pyx”, line 1905, in viktor.core._handle_job._handle_view
File “viktor\views.pyx”, line 1927, in viktor.views.View._wrapper
File “D:\viktor\EnergyAnalysis\app.py”, line 28, in displacement_plot
generic_analysis.execute(timeout=120)
File “viktor\external\external_program.pyx”, line 335, in viktor.external.external_program.ExternalProgram.execute
File “viktor\external\external_program.pyx”, line 337, in viktor.external.external_program.ExternalProgram.execute
File “viktor\external\generic.pyx”, line 81, in viktor.external.generic.GenericAnalysis._write_job_content
NotImplementedError

The code is:

def displacement_plot(self, params, **kwargs):
        building = params.building
        print(building)
        # Generate the input file(s)
        files = [
            ('building.txt', building)
            #('input2.txt', file2)
        ]

        # Run the analysis and obtain the output file.
        generic_analysis = GenericAnalysis(files=files, executable_key="countdown", output_filenames=["figure.json"])
        generic_analysis.execute(timeout=120)
        output_file = generic_analysis.get_output_file("figure.json")
        figure = plotly.io.read_json(output_file, output_type='Figure', skip_invalid=False, engine=None)
        return PlotlyResult(figure.to_json())

What am I doing wrong? How do you pass a file that has been uploaded to the web app? Thanks

Hi,

As you can see in the documentation here, the files should be of type BytesIO or File. If you check the type of params.building by using

print(params.building)

You will see it is of type FileRessource. To acces the File object for your analysis, you can use

building = params.building.file

kind regards,
Paulien

2 Likes

Perfect! That solved it! Thank you!