[BUG-305] Trying to send multipart/form-data

I am trying to integrate Ignition with a knowledgebase software, BookStack, and would like to send it some of the reports that we generate.

Bookstack’s HTTP API allows this, but requires the data comes through as Content-Type of multipart/form-data.

From what I have now read from other forum posts and the Ignition docs, neither system.net.httpPost or system.net.httpClient and the corresponding .post() function do not support multipart/form-data.

Is there a function or a library that I can use to send multipart/form-data?

You’re correct that system.net.httpPost and system.net.httpClient with .post() do not support multipart/form-data at this time. We currently have an internal ticket for this, but there is not a specific timeline for when it will be done.

You can use the python 2.7.0 requests module to run an HTTP request for multipart/form-data. It can be downloaded here:
Python 2.7.0 Requests Module: requests · PyPI

To import this module, you would take the “requests” folder from the source distribution and add it to the Ignition install directory and restart the gateway.
For more information on those steps, you can reference this article.

Sorry to reply so late to this, we have added the requests module and restarted the gateway and are getting an
ImportError: No module named urllib3
when trying to import the requests module

The Python requests module requires the urllib3 module and depending on which version you downloaded, you’ll have to add it yourself.
Around version 2.16.0, urllib3 stopped being bundled with the requests module according to their release logs (Community Updates — Requests 2.27.1 documentation).

Based on those release notes, if you download a version prior to that one then you won’t encounter that error as the urlib3 module will be included in the requests folder under a folder named “packages” otherwise you’ll need to downloaded the respective urllib3 module that is supported by the request module as stated in the release notes. In addition to urlib3, you would also require the chardet module to use requests.

As Python 3.4 support ended for requests at 2.22.0, you may run into some issues with any version of requests above that. For your information as well, adding a python module in pylib doesn’t require you to restart the gateway, but you will have to restart any active Designer or Vision Clients to receive any updates to the pylib folder.