我在 django 视图中有这个方法可以将文件发布到不同的服务器.我收到一个 HTTP 415 错误,抱怨请求的媒体类型.我已经调试了请求并将其内容复制并粘贴到 fiddler 中.当我从提琴手发布相同的内容时,它起作用了.所以我不明白为什么它不能使用 python requests 包.
Hi so I have this method in django views to post the file to a different server. I get an HTTP 415 error complaining about the media type of the request. I have debugged the request and copied and pasted its contents in fiddler. When I posted the same from fiddler it worked. So I don't understand why it does not work using python requests package.
谁能帮我解决这个问题?
Can anyone help me with this?
谢谢.
def upload(request): if request.method == 'POST': url=settings.WEBSERVICES_URL+'validate' r = requests.post('localhost:9090/validate',data=request) r2 = requests.get('localhost:9090/test') return render_to_response("upload.html", context_instance=RequestContext(request)) else: return render_to_response("upload.html", context_instance=RequestContext(request)) 推荐答案这样做:
r = requests.post('localhost:9090/validate', data=request.POST)当您只需要其发布数据时,您将一个完整的 django.http.HttpRequest 对象传递给 requests.post.
You are passing a full django.http.HttpRequest object to requests.post, when you only need its post data.
更多推荐
如何将 Django 请求发布到外部服务器
发布评论