[英]How to POST an MP4 using Python requests?
我正在嘗試使用request.post上傳MP4文件。 我不確定是否是由於文件大小所致,因為文件大小為3.2MB,而且我看到有人說他們的文件大小超過1.5MB。 任何幫助表示贊賞。 謝謝
def post_video(URL):
files = {'file': open(file_path, 'rb')}
response = requests.post(URL, files=files)
return response
響應代碼應該為204,但是返回500。請求在Swagger UI上有效
它不會讓我發表評論,
最可能的原因是您沒有在所需的帖子中添加標題。 我將查看REST API的文檔,甚至查看Swagger UI,然后進入開發人員控制台,觀察輸出並確保您添加了所需的一切。
標頭通常包含內容類型,有時還包含身份驗證令牌,您是否已通過端點進行身份驗證?
這是我的主張的一個例子:
def getresponse:
userpass = b64encode(b"<username>:<password>").decode("ascii")
headers = {'Content-type':'video/mp4', 'Authorization': 'Basic ' + userpass}
files = {'file': open(file_path, 'rb')}
response = requests.post(URL, files=files, headers=headers)
return response
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.