title: How to read blob data in Python
body: <p>From Salesforce File, I want to read the file and get the content between some text and store it in the Custom object record field.
  For this, I have created an external API(python script deployed to heroku) where I am sending the file content as blob(basically the content of the file is Blob in Salesforce
  ).
  Now I want to read the file and get the text. But I was not able to read the blob data.
  If I convert the blob to string in SF while posting and decode it in python also doesn't work. Please give some inputs on this. I am new to python.</p>
  <p>my python code :</p>
  <pre class="lang-py prettyprint-override"><code>from flask import Flask, request, jsonify
  import base64
  import blob
    
  app = Flask(__name__)
  
  @app.route('/get/record/', methods=['GET', 'POST','DELETE', 'PATCH'])
  def index():
      if request.method == 'POST':
          print(&quot;===inside===&quot;)
          payload_list = request.get_json(force=True)           
          print(&quot;====next line payload_list ===&quot;)
          print(blob(payload_list[&quot;BlobData&quot;])
          # responseStr = str(payload_list[&quot;BlobData&quot;])
          # print(&quot;===decodedata===&quot;)
          # print(base64.b64decode(responseStr))
    return &quot;sucesss&quot;
  </code></pre>
  <p>Salesforce Rest Code:</p>
  <pre><code>List&lt;ContentVersion&gt; cv = [SELECT ContentDocumentId,VersionData from ContentVersion
                              where ContentDocumentId = 'xxxxxxxxxx' order by CreatedDate DESC];
  String bodyEncoded = EncodingUtil.base64Encode(cv[0].versiondata);
  Http http = new Http();
  HttpRequest request = new HttpRequest();
  request.setEndpoint('https://realpyth.herokuapp.com/get/fileService/');
  request.setMethod('POST');
  request.setHeader('Content-Type', 'application/json');
  request.setBody('{&quot;BlobData&quot;:&quot;'+cv[0].versiondata+'&quot;}'); // Send the data as Blob
  //request.setBody('{&quot;BlobData&quot;:&quot;'+bodyEncoded+'&quot;}'); // Convert the blob data and send as String
  HttpResponse response = http.send(request);
  if (response.getStatusCode() != 201) {
  System.debug('=======' +response.getStatusCode() + ' ' + response.getBody());
  } else {
  System.debug('====response==='+response.getBody());
  }
  </code></pre>