Как отправить 2 запроса успев попасть в 1 поток на asp на python?

На сайте есть функция отправки сообщения, делается запросом - InboxMail, но если я хочу взять и отправить вместе с сообщением еще один файл, вызывается еще один запрос - FileChunkSave, который берет вытаскивает из ответа запроса InboxMail переменную messageID и прикрепляет указанный файл. Если я беру последовательно отправляю 2 запроса то сервер дает такой ответ

unexpected end of stream, the content may have already been read by another component неожиданный конец потока, содержимое, возможно, уже было прочитано другим компонентом

Как я могу исправить эту ошибку "unexpected end of stream, the content may have already been read by another component"? Ошибка

Мой код

import requests
import json

headers = {}

def tokenAuth():#Получаем токен
    url = "https://test.mmis.ru/api/tokenauth"
    dataLogPass = {"userName": "student", "password": "testMe"}
    response = requests.post(url, json = dataLogPass)
    response = json.loads(response.text)['data']['data']
    token = response['accessToken']
    headers.update({'Cookie':'authToken='+token})
    sendMail()

def sendMail():#Отправляем сообщение
    url = "https://test.mmis.ru/api/Mail/InboxMail"
    headers.update({'Content-Type':'application/json;charset=utf-8'})
    payload = {
        "htmlMessage":"",
        "message":"",
        "markdownMessage":"1",
        "theme":"Python",
        "userToID":[{
            "id": 1136,
            "email":"[email protected]",
            "fio": "Петров Петр Иванович"}]}
    payload = json.dumps(payload)
    response = requests.post(url,headers = headers, data = payload)
    messageID = json.loads(response.text)['data']["messageID"]
    del headers['Content-Type']
    FileChunkSave(messageID)

def FileChunkSave(messageID):# Сохранение файла
    url =  "https://test.mmis.ru/api/Mail/FileChunkSave"
    headers.update({'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundaryRCDYViXYfnieA2py'})
    files = {'testfile.docx': open(r"C:\Users\Loki\Downloads\testfile.docx", 'rb')}
    payload = {"messageID":messageID,"isFirstChunk":True,"isLastChunk":True}
    response = requests.post(url,headers=headers,data=payload,files=files)
    del headers['Content-Type']


tokenAuth()

Ответы (1 шт):

Автор решения: Sebastian Dorado

Сервер на который я отправляю в обязательном порядке требует правильно сгенерированную переменную WebKitFormBoundary для файла, то есть границы ключа.

def fileCoursesSave(idTask,courseTaskID):

fields = {
    'newFiles': ('testfile.docx', "multipart/form-data"),
    'file_id': "0",
    "studentID":str(data['idAdverse']),
    'courseTaskID':courseTaskID,
    'courseStudentID':idTask
}
boundary = '----WebKitFormBoundary' \
           + ''.join(random.sample(string.ascii_letters + string.digits, 16))
m = MultipartEncoder(fields=fields, boundary=boundary)

headers.update({
    "Host": "test.mmis.ru",
    "Connection": "keep-alive",
    "Content-Type": m.content_type
})
req = requests.post(host+"/api/ElectronicEducation/FileSave",headers=headers,data=m)
print(req.text)
→ Ссылка