문제

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("http://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("http://127.0.0.1:8090/", data=form_data, files=files)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top