Home > database >  Convert client requests to proper requests for custom highchart node export server
Convert client requests to proper requests for custom highchart node export server

Time:02-21

Im trying to export images by a custom node export server. server is running and when I send requests directly to server everything is fine.

    exporting: {
    url: "http://ip:7779"
},

But for some security reasons first I need to send request to my flask server, I checked incoming request and it contain this values:

CombinedMultiDict([ImmutableMultiDict([]), ImmutableMultiDict([('width', u'0'), ('scale', u'2'), ('type', u'image/png'), ('filename', u'chart'), ('svg', u'<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"  ...omited!')])

and content type is like multipart/form-data; boundary=----WebKitFormBoundaryt7Gcilm12pNBmSab

so I changed my code:

    url: "/highchart"
},
@app.route('/highchart', methods=["GET", "POST"])
@login_required
def highchart_export():
    try:
        data = {}
        for i in request.values:
            data[i] = request.values[i]
        response = requests.post('http://0.0.0.0:7779',data=data)
        return response.text, response.status_code, response.headers.items()
    except:
        print traceback.format_exc(sys.exc_info())

But it not work. I just get an image with text "It appears that we don't support this file format."

CodePudding user response:

It seems in my code some headers and part of body is missing so for a clean redirect I used this code:

response = requests.request(
    method=request.method,
    url='http://127.0.0.1:7779',
    headers={key: value for (key, value) in request.headers},
    data=request.get_data(),
    cookies=request.cookies,
    allow_redirects=False)
headers = [(name, value) for (name, value) in response.raw.headers.items()]
return Response(response.content, response.status_code, headers)

And now output is fine.

  • Related