No /GET endpoint when using flask-restx with Python

Using RStudio Connect to deploy a flask API from python (rsconnect library). I really like the idea of adding swagger docs so using the flask-restx package, with guiding examples from RStudio docs ( and

Following this though, I'm getting this error upon deployment using rsconnect: " You are seeing this page because the Python API at this location does not provide a resource at the root ( GET / )". Has anyone ever encountered this before? If so, any troubleshooting advice?

I'm including my code below for added clarity:

## file is named:

model = hub.load(model_folder)

def  make_prediction(*, input_data) -> dict:
    """Make a prediction using saved tf model.
        input_data: Array of model prediction inputs.
        Predictions for each input row

    data = tf.convert_to_tensor([input_data])
    ## loaded above
    prediction = model(data).numpy()

    return prediction.tolist()

app = Flask(__name__)

## added this because I kept getting CORS error-- hiding the actual server route here though
## this deviates from the RStudio example so maybe here?

app.config["SERVER_NAME"] = "base_url:port/content/#/"

# define the flask-restx boilerplate

api = Api(
    title="Model API", 
    description="Predicts something"

# define the main subroute for requests

ns = api.namespace("predict", description="Predict something")

# define the API response

model_predict = api.model(
        "input": fields.String(required=True, description="text"),
        "output": fields.Float(description = "Predicted")

# GET example that accepts a new data point as a query parameter in the URL path
# served at route + namespace, so at /predict/<user's text input>

@ns.param("input", "new text")
class Predict(Resource):
    @ns.doc("get text ")
    def get(self, input):
        prediction = make_prediction(input_data=input)
        return jsonify({'output': prediction,  'input': input})

Hi @markpreston,
As you suspected -- This line where you're trying to set base_url as your hostname is creating an issue:

We'll be adding CORS support in the next release of Connect which should enable you to remove that app.config line. In the meantime you may need to use a proxy to get around CORS, but I'll have your CS rep reach out with more information on when to expect our next release.

Okay glad to have that feedback. How does proxying work? Do you have any suggested routes to get around the issue aside from that? Avoiding the flask-restx package until the update? Any insight would be much appreciated. Thanks for the starting point though :slight_smile:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.