How to use HTTP/POST service (docker container) with dictionnary that has images? (Include an example, please?)
Created originally on Bitbucket by tadauzis (Tadas U)
I found an example, e.x.
#!python
# fusion API needs those 3 keys
fields = {
"targetformat": targetformat,
"datadict": json.dumps(data_s),
"image_mapping": "{}",
}
# and it needs to receive a POST with fields and files
r = requests.post(url, data=fields, files=files)
Where "data_s" in my example is:
#!python
data_s = {
'records': [
{'title': 'first', 'image': base64.b64encode(open('example.png', 'rb').read())},
{'title': 'second', 'image': base64.b64encode(open('example.png', 'rb').read())},
]
}
I am trying to b64encode, because otherwise I get json encoding errors; Event with this option on frame in my odt template: "py3o.image(r.image, 'png', isb64=True)"
I get an error "{u'reasons': [u"IOError('cannot identify image file <cStringIO.StringI object at 0x7f6ff01e6c68>',)"], u'error': True}"