如何将 Django 请求发布到外部服务器

编程入门 行业动态 更新时间:2024-10-28 20:29:29
本文介绍了如何将 Django 请求发布到外部服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 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 请求发布到外部服务器

本文发布于:2023-10-12 17:47:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485425.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   服务器   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!