How do I (safely) send a Python object to my Flask API? How do I (safely) send a Python object to my Flask API? json json

How do I (safely) send a Python object to my Flask API?


When you pickle the object in python 3, pass the protocol keyword and set it to 2. This will ensure that it will work on python 2.

import requestsimport pickleurl = "http://localhost:5000/flask-api-function"# the object I want to send is the 'model' objectdata = pickle.dumps(model,protocol=2)r = requests.post(url,data=data)

Generally I would try to find a way to serialize the object into JSON since pickle has major security risks