biosimulators / Biosimulators_utils

Utilities for building standardized command-line interfaces for biosimulation software packages
https://docs.biosimulators.org/Biosimulators_utils
MIT License
4 stars 6 forks source link

Debug simulation submission to runBioSimulations via files with Python #66

Closed jonrkarr closed 2 years ago

jonrkarr commented 2 years ago

@bilalshaikh42 I can't figure out how to use Python to submit simulations programmatically to runBioSimulations. Do you know what's wrong?

import json
import requests
archive_filename = '/path/to/archive.omex'
run = {
    "name": 'test',
    "simulator": 'copasi',
    "simulatorVersion": 'latest',
    "cpus": 1,
    "memory": 8,
    "maxTime": 20,
    "envVars": [],
    "email": None,
    "public": False,
}
with open(archive_filename, 'rb') as archive_file:
    response = requests.post(
        'https://run.api.biosimulations.org/runs',
        files={
            'simulationRun': (None, json.dumps(run)),
            'file': ('project.omex', archive_file, 'application/zip'),
        },
        headers={
            "Content-Type": "multipart/form-data",
            "Accept": "application/json",
        }
    )
response.raise_for_status()
print(response.json())
jonrkarr commented 2 years ago

I will put the correction in biosimulators_utils.biosimulations.utils.submit_project_to_runbiosimulations.

bilalshaikh42 commented 2 years ago

That looks fine to me. Is there any error message received? I know the Axios library in javascript will simply not execute a request if the multipart/form-data is not constructed properly. Does requests have some sort of object to construct form data with? I think It could be worth using the client library at biosimulations/client to avoid needing to make the request manually.

jonrkarr commented 2 years ago

The request returns a 500 error.

The request looks fine to me too. The must be an issue with the form or JSON encoding.

These requests seemed simple enough to just use the requests package. I can use the client library instead. Can you push it to PyPI?

jonrkarr commented 2 years ago

The Content-Type header needed to be removed because the requests package sets this. With this set, the boundary between multi-part form elements is incorrect.