title: How to send python class objects using flask and pickle
body: <p>I have the following code</p>
  <p>client.py</p>
  <pre><code>import requests
  import pickle
  
  class Test():
      def __init__(self, val):
          self.val = val
  
  testList = []
  for i in range(0,10):
      testList.append(Test(i))
  
  
  
  data = {&quot;foo&quot;: 1000, &quot;bar&quot;: &quot;value&quot;, &quot;list&quot;: testList}
  endpoint = &quot;%s/%s&quot; % (address, &quot;testendpoint&quot;)
  r = requests.post(endpoint, data={&quot;req&quot;: pickle.dumps(data) })
  </code></pre>
  <p>server.py</p>
  <pre><code>import flask
  import pickle
  from flask import request
  
  app = flask.Flask(__name__)
  app.config[&quot;DEBUG&quot;] = False
  
  class Test():
      def __init__(self, val):
          self.val = val
  
  @app.route('/testendpoint', methods=['POST'])
  def testendpoint():
      data = pickle.loads(request.form['req'])
      print(data)
  
      response = {
          &quot;response&quot;: &quot;Success&quot;
      }
  
      return json.dumps(response)
  
  app.run(host=&quot;0.0.0.0&quot;, port=24979)
  </code></pre>
  <p>When I run client.py with server.py running, I get the following error:</p>
  <pre><code>[2020-07-17 14:06:05,054] ERROR in app: Exception on /testendpoint [POST]
  Traceback (most recent call last):
    File &quot;/usr/local/lib64/python3.6/site-packages/flask/app.py&quot;, line 2446, in wsgi_app
      response = self.full_dispatch_request()
    File &quot;/usr/local/lib64/python3.6/site-packages/flask/app.py&quot;, line 1951, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File &quot;/usr/local/lib64/python3.6/site-packages/flask/app.py&quot;, line 1820, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File &quot;/usr/local/lib64/python3.6/site-packages/flask/_compat.py&quot;, line 39, in reraise
      raise value
    File &quot;/usr/local/lib64/python3.6/site-packages/flask/app.py&quot;, line 1949, in full_dispatch_request
      rv = self.dispatch_request()
    File &quot;/usr/local/lib64/python3.6/site-packages/flask/app.py&quot;, line 1935, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File &quot;server.py&quot;, line 11, in testendpoint
      data = pickle.loads(request.form['req'])
  TypeError: a bytes-like object is required, not 'str'
  </code></pre>
  <p>I assume my bytes object gets converted to a string when sent via the http request. How do I send my data on the client via the request and then decode it on the server end?</p>