SIMBAChain / libsimba.py-platform

MIT License
1 stars 0 forks source link

fixed method calls with files #17

Closed bpbirch closed 2 years ago

bpbirch commented 2 years ago

We were unable to submit multipart-form data, for a few main reasons: 1) in SimbaContract.call_contract_method_with_files, we were automatically converting json_payload to json.dumps(json_payload), converting our inputs to string 2) in SimbaRequest.send(), we were calling headers.update({'content-type': 'application/json'}) for all posts, even those including files, which prevents httpx from creating boundary headers for multipart/form-data requests 3) as 1) references, we actually need to be passing inputs as {"str_key": "str_val"}, rather than '{str_key: str_val}'. adding string_keys_and_vals = {str(key): str(val) for key, val in json_payload.items()} fixes this

whelks-chance commented 2 years ago

I might be wrong, but isn't there an issue with sending json and files in the same http post? Especially nested json beyond simple string key-value pairs.

bpbirch commented 2 years ago

@whelks-chance - as far as I understand, when we're sending multipart/form-data, we should be passing our other data as string values. This was an issue I've run into in other SDK bindings, and one that Andrew advised me on. For reference, I was using the httpx docs: https://www.python-httpx.org/quickstart/. particularly: Screen Shot 2022-03-09 at 7 56 41 AM