10

I am uploading a file using requests library below is the code:

files = {'file': open(full_file_name, 'rb')}
headers = {"content-type": 'application/x-www-form-urlencoded'}
final_resp = requests.put(loc, files=files, headers=headers)

The problem is some extra contents have been added to the file's start and end point.

The contents added to the start point is:

--b16010ae7646a031a5adc64ac0661e72
Content-Disposition: form-data; name="file"; filename="1016064585-65769268.csv"

The contents added to the endpoint is:

--b16010ae7646a031a5adc64ac0661e72--

But when the same file is uploaded through the postman these problems are not arising.

here is the screenshot of the postman enter image description here.

The header of the postman is:

application/x-www-form-urlencoded

1
  • Data is required, such as I see from the URL, you should attach your username, and etc. please show us the params page of postman Commented Feb 12, 2019 at 14:59

1 Answer 1

23

it may because you use multipart/form to upload file.try use data like code below

data = open(localFilePath, 'rb').read()
headers = {
    "Content-Type":"application/binary",
}
upload = requests.put(uploadUrl,data=data,headers=headers)
Sign up to request clarification or add additional context in comments.

1 Comment

It worked for me, with "data" it adds nothing to the header/bottom file (in this case audio file).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.