Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

docker - HTTPS POST calls are ignored by flask

i have 2 flask containers. one is listening on port 80 for http calls and the other one is listening on port 443 for https calls. both are supposed to respond to GET and POST calls. the http (port 80) server works fine for both GET and POST. the https (port 443) server works fine for GET calls but from some unclear reason it seems that POST calls are blocked somewhere and don't go through to the flask server.

this is the app.py of the http flask server:

from flask import Flask, request
import requests
app = Flask(__name__)

@app.route('/', defaults={'u_path': ''}, methods=['GET',"POST"])
@app.route('/<path:u_path>', methods=['GET',"POST"])
def redirectChannels(u_path):
    print(repr(u_path))
    print(request.base_url)
    print(request.url)
    print(request.method)
    print(request.values)

    res = ""
    if request.method == "GET":
        ans = requests.get(request.url)
        res = ans.text
    elif request.method == "POST":
        res = requests.post(request.url, data=request.values)

    return res


@app.before_request
def log_request_info():
    print('Headers: %s', request.headers)
    print('Body: %s', request.get_data())


if __name__ == "__main__":
    app.run(host ='0.0.0.0', port = 5000, debug = True)

and this is the app.py of the https flask server:

from flask import Flask, request
import requests
import sys, traceback
import json
app = Flask(__name__)

@app.route('/', defaults={'u_path': ''}, methods=['GET','POST'])
@app.route('/<path:u_path>', methods=['GET','POST'])
def redirectChannels(u_path):
    print(repr(u_path))
    print(request.base_url)
    print(request.url)
    print(request.method)
    print(request.values)

    res = ""
    if request.method == "GET":
        ans = requests.get(request.url)
        res = ans.text
    elif request.method == "POST":
        res = requests.post(request.url, data=request.values)

    return res

@app.before_request
def log_request_info():
    print('Headers: %s', request.headers)
    print('Body: %s', request.get_data())

if __name__ == "__main__":
    app.run(host ='0.0.0.0', port = 5000, debug = True, ssl_context='adhoc')

i actually think it can be related to a configuration in the containers port mapping. when running docker ps i'm getting this: docker ps result

not sure i understand the 443/tcp under PORTS in both containers and i believe it might be related to my problem. can anyone explain it?

question from:https://stackoverflow.com/questions/65640678/https-post-calls-are-ignored-by-flask

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...