0

I have send requests with python to upload file.

When I don't add content-type in heards, I can success upload file:

import requests
import csv
import os
url = "https://url/upload/"

headers = {
    'authority': 'https://url/',
}
csv_file_path = os.getcwd() + r"\xxx.csv"

files = {
        "file":  open(csv_file_path, "rb")
    }

response = requests.post(url, headers=headers, files=files)

print(response.text.encode('utf8'))

But if I add 'content-type': 'multipart/form-data'(get it from browser) in headers, will upload fail(500 error).

Why can't using this content-type? what is correct content-type?

Thank for answer!

Yu jen
  • 23
  • 6
  • for json text, it should be `application/json` under `'content-type'`. – de_classified Jul 31 '20 at 08:51
  • @FishingCode thank you. I sending binary file, I have try if using `application/json` still got fail. – Yu jen Jul 31 '20 at 08:56
  • possibly look into this [link](https://stackoverflow.com/questions/9254891/what-does-content-type-application-json-charset-utf-8-really-mean) for utf-8 encoding it maybe a litle different. – de_classified Jul 31 '20 at 09:03

0 Answers0