Python请求使用多部分表单数据发布,而不上载文件

Python请求使用多部分表单数据发布,而不上载文件,python,http-post,multipartform-data,Python,Http Post,Multipartform Data,我想在不上传文件的情况下发布数据,我已经尝试了所有可能的方法,但无法做到 ------WebKitFormBoundary1Pofu6UFaasCiaLP Content-Disposition: form-data; name="csrfmiddlewaretoken" MJl9tuO3473PMg1NfG2ih6wAIbBJ2Tehamd0WXmZlyqPtOcKaT6XQr9e3PGLtPQo ------WebKitFormBoundary1Pofu6UFaasCi

我想在不上传文件的情况下发布数据,我已经尝试了所有可能的方法,但无法做到

------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="csrfmiddlewaretoken"

MJl9tuO3473PMg1NfG2ih6wAIbBJ2Tehamd0WXmZlyqPtOcKaT6XQr9e3PGLtPQo
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="name"

adg_lt10
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="email"

adg_lt10@yopmail.com
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="city"

Yanbu
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="saudi_national"

true
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="gender"

m
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="phone_number"

+923134147647
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="birth_day"

14
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="birth_month"

6
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="birth_year"

1992
------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="organization"


------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="linkedin_url"


------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="resume"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary1Pofu6UFaasCiaLP
Content-Disposition: form-data; name="delete-file"

No
------WebKitFormBoundary1Pofu6UFaasCiaLP--
有人能帮忙吗?我尝试了几件事,比如下面的代码,但我不断从服务器收到错误的请求

有任何有效的例子吗

以下是代码:

    def fill_contact_form(self, email, username):
        url = self.hostname + '/application/contact'
        response = self.session.get(url)
        soup = BeautifulSoup(response.text)
        middlewaretoken = soup.find('input', {'name': 'csrfmiddlewaretoken'})['value']
        token = response.cookies['csrftoken']
files = {"file": ('resume', open('test.jpg', "rb"), 'application/octet-stream')}
        fields = {
            "csrfmiddlewaretoken": middlewaretoken,
            "name": username,
            "email": email,
            "city": "Medina",
            "saudi_national": "true",
            "gender": "m",
            "phone_number": "+123435678910",
            "birth_day": "15",
            "birth_month": "6",
            "birth_year": "1990",
            "organization": "",
            "linkedin_url": "",
            "delete-file": "No"
        }
resp = self.session.post(url, data=fields, files=files)

我做错了什么,知道吗?

你能分享一下代码片段吗?我不确定这个输出是什么of@vegabondx刚刚更新我看你能详细说明一下“不上传文件”是什么意思吗?你为什么要这么做?上传文件时,什么不起作用?你说的是哪个文件(我猜是test.jpg)我说的对吗?@vegabondx我不想上传任何文件。你可以说我想发送文件参数empty和字段dict.Hmm中设置的其他数据,如果你只是从帖子中删除文件,它会抛出什么错误(我检查aiohttp referece,我认为文件不是必需的参数),也就是说,如果你不发送文件,它会对数据感到满意。我不确定如果您的服务器配置为查看该文件,它是否会引发任何异常。