![](/img/trans.png)
[英]Python: Getting “internalServerError:500” while trying to use requests.post
[英]HTTPError: 500 while trying to post data using requests.post() in Django framework (python program)
有人請在這里幫助我。 我正在嘗試處理目錄中的幾個文本文件並將它們轉換為字典。 Then I'm trying to upload through the DJANGO REST API using requests.post()
but I'm getting requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http://34.72.26.221/feedback
.
我的代碼如下:
#!/usr/bin/env python3
import os
import requests
import glob
dirloc = r"/data/feedback/"
d = {}
for file in glob.iglob(dirloc+ '*'):
if not file.startswith('.'):
with open(file,'r') as f:
d["title"] = f.readline().strip("\n")
d["name"] = f.readline().strip("\n")
d["date"] = f.readline().strip("\n")
d["feedback"] = f.readline().strip("\n")
print(d) #used for troubleshooting only#
r = requests.put("http://34.72.26.221/feedback/", data = d)
print(r.status_code)
我是編碼新手,但仍在弄清楚事情。 所以這篇文章可能缺少一些需要的信息。 如果我需要添加任何內容,請告訴我。
你沒有使用post
你正在使用put
和requets.put
。
將您的requests
用法更改為:
r = requests.post("http://34.72.26.221/feedback", data = d)
正如錯誤告訴 5**,您的 django 視圖存在問題。 如果可能,請分享您的 django 查看代碼以幫助您解決問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.