How to upload a Binary STL to Windchill using REST API in python?

I have been able following the Windchill support link www.ptc.com/en/support/article/cs330694
to upload an ASCII file (including an STL file). However, when I try to upload a binary file, the file which gets uploaded to the Windchill is corrupted.

I am using Requests python module for http client. This is a multipart/form POST.
I read the Binary stream using this code:

with open(files[0], 'rb') as f: content = f.read()

Then simply I form the payload “Body” of the request following the instruction in the above link.
where I simply add the content to the string using the format(entry1, entry2,..)
entry2 = content

I tried to trim the leading b’ and tail ‘
That resulted in the following:
When I compare reading the original STL file to the uploaded one I get this difference for reading the only 100 first bytes:

original:
b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\x91\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?\xcd\xec\xd7C’
uploaded:
b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00′
so there are two backslashes \ instead of only one backslash \

Read more here: Source link