Python多部分POST格式错误
我正在尝试了解如何使用Python将多部分POST请求写入OneNote。以下是我迄今为止所做的工作:Python多部分POST格式错误,python,post,request,onenote,onenote-api,Python,Post,Request,Onenote,Onenote Api,我正在尝试了解如何使用Python将多部分POST请求写入OneNote。以下是我迄今为止所做的工作: url = ROOT_URL+"pages" headers = {"Content-Type":"multipart/form-data; boundary=MyAppPartBoundary", "Authorization" : "bearer " + access_token} txt = """--MyAppPartBoundary
url = ROOT_URL+"pages"
headers = {"Content-Type":"multipart/form-data; boundary=MyAppPartBoundary",
"Authorization" : "bearer " + access_token}
txt = """--MyAppPartBoundary
Content-Disposition:form-data; name="Presentation"
Content-type:text/html
<!DOCTYPE html>
<html>
<head>
<title>One Note Text</title>
</head>
<body>
<p>Hello OneNote World</p>
</body>
</html>
--MyAppPartBoundary--
"""
session = requests.Session()
request = requests.Request(method="POST", headers=headers,
url=url, data=txt)
prepped = request.prepare()
response = session.send(prepped)
给出了这个错误。我做错了什么?第一个预感:确保请求正文中的换行符是CRLF(而不仅仅是LF)。
multipart的规范对第一个预感非常挑剔:确保请求正文中的换行符是CRLF(而不仅仅是LF)。
multipart的规范对这一点非常挑剔看起来您在Thank you上回答了自己的问题,这是其中的一部分!我需要“\r\n”而不仅仅是“\n”。这是迄今为止最大的问题!我在解决方案中也注意到了一些其他的差异。看起来你在“谢谢”中回答了自己的问题,这是其中的一部分!我需要“\r\n”而不仅仅是“\n”。这是迄今为止最大的问题!我在解决方案中也注意到了一些其他的差异。
url = ROOT_URL+"pages"
headers = {"Content-Type":"multipart/form-data; boundary=MyAppPartBoundary",
"Authorization" : "bearer " + access_token}
txt = """<!DOCTYPE html>
<html>
<head>
<title>One Note Text</title>
</head>
<body>
<p>Hello OneNote World</p>
</body>
</html>"""
files = {'file1': ('Presentation', txt, 'text/html')}
session = requests.Session()
request = requests.Request(method="POST", headers=headers,
url=url, files=files)
prepped = request.prepare()
response = session.send(prepped)
headers = {"Content-Type":"multipart/form-data; boundary=MyAppPartBoundary",
"Authorization" : "bearer " + access_token}
files = {'file1': ('filename', 'data', 'text/plain')}
r = requests.post(url, headers=headers, files=files)