将多部分/表单数据转发到不同的服务(Python,瓶子,请求)

编程入门 行业动态 更新时间:2024-10-27 10:27:55
本文介绍了将多部分/表单数据转发到不同的服务(Python,瓶子,请求)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个中间层api,它从客户端接收请求(可能带有附件的表单提交请求),并验证两件事(使用WTForms进行表单验证),然后将表单发布请求转发到实际上对此执行操作的另一个服务.

I have middle-layer api which receives request (form submit request with possibly with attachment) from client and verify couple of things (form validation using WTForms) and then forward form post request to another service which actually performs actions on that.

我面临的问题无法按原样转发请求数据和附加的文件,下面是代码示例.

Problem I am facing is not able to forward request data and files attached as it is, below is code example.

@post('/') def index(): post_data = request.POST.dict requests.post("127.0.0.1:8090/", data=post_data, files=request.files)

推荐答案

弄清楚了如何使其工作,实际上我做错了,下面的代码可以工作

Figured out how to make it work, actually something that I was doing wrong, code below will work

@post('/') def index(): form_data = request.form.dict file_data = request.files.get("myfile", "") files = {file_data.name: (file_data.filename, file_data.file, file_data.type)} requests.post("127.0.0.1:8090/", data=form_data, files=files)

更多推荐

将多部分/表单数据转发到不同的服务(Python,瓶子,请求)

本文发布于:2023-11-15 09:22:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   瓶子   数据   Python

发布评论

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

>www.elefans.com

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