0

I have a file called sth.py with following content:

print('20')
print(2+3)

when I make a curl

curl -u log:pass -T filepath http://something/sth.py 

everything works great, when I download the file later It looks the same, when I do it with python requests like that:

files = {'sth.py': open(filepath, 'rb')}
auth = (log, pass)
r = requests.post('http://something/sth.py', files=files, auth=auth)

It also gets uploaded, but after I download it from the server it looks like this:

--3541f6ca4fc1fc7a26a3bef9ee42edcc
Content-Disposition: form-data; name="sth.py"; filename="sth.py"

print('20')
print(2+3)

--3541f6ca4fc1fc7a26a3bef9ee42edcc--

What's the problem?

  • Your `curl` command doesn't make a multipart/form post. Use `data=open(filepath, 'rb')` instead of using `files=...`. – Martijn Pieters Dec 09 '19 at 16:47
  • See my answer to the duplicate, the part where I write: *If you are meaning the whole POST body to be taken from a file (with no other fields specified)*. – Martijn Pieters Dec 09 '19 at 16:48

0 Answers0