title: Uploading Office Open XML files using API POST method in Python
body: <p>I am trying to write a script to help me automate some work with our CAT tool (Memsource). To this end, I need to upload some files using API.</p>
  <p>I rely on Memsource API documentation available here: <a href="https://cloud.memsource.com/web/docs/api#operation/createJob" rel="nofollow noreferrer">https://cloud.memsource.com/web/docs/api#operation/createJob</a></p>
  <p>I wrote a short code to test file uploading before moving to making it async, and I have some serious problem: text files are uploaded correctly, although the body of the text contains some additions after uploading:</p>
  <pre><code>--4002a5507da490554ad71ce8591ccf69    
  Content-Disposition: form-data; name=&quot;file&quot;; filename=“test.txt&quot;
  </code></pre>
  <p>I also tried to upload DOCX file, but it cannot be even opened in Memsource online editor — I guess the content is modified along the way, but I am unable to find where...</p>
  <p>The code responsible for the upload is as follows:</p>
  <pre><code>def test_upload(self):
      # Assemble &quot;Memsource&quot; header as mentioned in the API docs
      Memsource_header = {
          &quot;targetLangs&quot;: [&quot;pl&quot;],
      }
  
      # Open the file to be uploaded and extract file name
      f = open(&quot;Own/TMS_CAT/test.txt&quot;, &quot;rb&quot;)
      f_name = os.path.basename(f.name)
  
      # Assemble the request header
      header = {
          &quot;Memsource&quot;: json.dumps(Memsource_header),
          &quot;Content-Disposition&quot;: f'attachment; filename=&quot;{f_name}&quot;',
          &quot;Authorization&quot;: f&quot;ApiToken {self.authToken}&quot;,
          &quot;Content-Type&quot;: &quot;application/octet-stream; charset=utf-8&quot;,
      }
  
      # Make POST request and catch results
      file = {&quot;file&quot;: f}
  
      req = requests.post(
          &quot;https://cloud.memsource.com/web/api2/v1/projects/{project-id}/jobs&quot;,
          headers=header,
          files=file,
      )
      print(req.request.headers)
      print(req.json())
  </code></pre>
  <p>The request header:</p>
  <pre><code>{
     &quot;User-Agent&quot;:&quot;python-requests/2.27.1&quot;,
     &quot;Accept-Encoding&quot;:&quot;gzip, deflate&quot;,
     &quot;Accept&quot;:&quot;*/*&quot;,
     &quot;Connection&quot;:&quot;keep-alive&quot;,
     &quot;Memsource&quot;:&quot;{\&quot;targetLangs\&quot;: [\&quot;pl\&quot;]}&quot;,
     &quot;Content-Disposition&quot;:&quot;attachment; filename=\&quot;test.txt\&quot;&quot;,
     &quot;Authorization&quot;:&quot;ApiToken {secret}&quot;,
     &quot;Content-Type&quot;:&quot;application/octet-stream; charset=utf-8&quot;,
     &quot;Content-Length&quot;:&quot;2902&quot;
  }
  </code></pre>
  <p>And the response from Memsource:</p>
  <pre><code>    {
     &quot;asyncRequest&quot;:{
        &quot;action&quot;:&quot;IMPORT_JOB&quot;,
        &quot;dateCreated&quot;:&quot;2022-02-22T18:36:30+0000&quot;,
        &quot;id&quot;:&quot;{id}&quot;
     },
     &quot;jobs&quot;:[
        {
           &quot;workflowLevel&quot;:1,
           &quot;workflowStep&quot;:{
              &quot;uid&quot;:&quot;{uid}&quot;,
              &quot;order&quot;:2,
              &quot;id&quot;:&quot;{id}&quot;,
              &quot;name&quot;:&quot;Tra&quot;
           },
           &quot;imported&quot;:false,
           &quot;dateCreated&quot;:&quot;2022-02-22T18:36:30+0000&quot;,
           &quot;notificationIntervalInMinutes&quot;:-1,
           &quot;updateSourceDate&quot;:&quot;None&quot;,
           &quot;dateDue&quot;:&quot;2022-10-10T12:00:00+0000&quot;,
           &quot;targetLang&quot;:&quot;pl&quot;,
           &quot;continuous&quot;:false,
           &quot;jobAssignedEmailTemplate&quot;:&quot;None&quot;,
           &quot;uid&quot;:&quot;{id}&quot;,
           &quot;status&quot;:&quot;NEW&quot;,
           &quot;filename&quot;:&quot;test.txt&quot;,
           &quot;sourceFileUid&quot;:&quot;{id}&quot;,
           &quot;providers&quot;:[
              
           ]
        }
     ],
     &quot;unsupportedFiles&quot;:[
        
     ]
  }
  </code></pre>
  <p>both look okay to me...</p>
  <p>I will appreciate any suggestions on how to get this thing working! :-)</p>