0

I Have two API's one is basically for generating PDF's basing on the data sent.

This first API endpoint below

http://localhost:5000/api/sendReceiptData

Returns a PDF file as an attachment.

The second API will consume the first API and should return a PDF as an attachment in the response. I have tried it out but I get this error TypeError: Object of type bytes is not JSON serializable

How can I therefore return a file response from the first API within this second API

Kally
  • 324
  • 1
  • 4
  • 12

1 Answers1

2

You need to use send_file method to return pdf file

from flask import Flask, make_response, send_file

app = Flask(__name__)


@app.route("/pdf/<string:filename>")
def return_pdf(filename):

    return send_file(filename)


George Imerlishvili
  • 1,816
  • 2
  • 12
  • 20