0

I'm trying to use Amazon Textract but upon my API call it says allow-access-origin-header not present and makes the API not work. I have taken steps to see that the API itself does work but I can't use this to deploy to customers who want to use the OCR. Is there a python package or maybe a way to make it work?

  • I have tested with disable CORS chrome plugin
  • I have disabled CORS on chrome to test it
  • I have reconfigured API Gateway
  • I have added the headers to my json response on AWS Lambda

It is basically a browser problem so how do I add this header to it.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
ad stefnum
  • 78
  • 6

1 Answers1

1

First install this package

$ pip install -U flask-cors

then import it to your app.py and implement it like this

...
from flask_cors import CORS, cross_origin
...
app = Flask(__name__)
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
app.config['CORS_HEADERS'] = 'Content-Type'

@app.route("/api/something", methods=["POST"])
@cross_origin()
def something():
    return Response('{"something":"something else"}', status=200, mimetype='application/json')

Hope it helps :-)

mama
  • 2,046
  • 1
  • 7
  • 24
  • It's an API that is hosted on AWS lambda and API Gateway. It is a react is application. So it has no flask. The only python it has is the API – ad stefnum Jul 08 '20 at 10:59