Forums

Return json

Hi, sorry for the extreme noob question, but I can't figure this out.

I need to send some data (i.e, a list of words) from a Google Script to my script in PA, process it, and then return a json back to GS.

I can't do that, everytime it returns an error and I don't understand why, I'm using reqbin to test it and it just doesn't work.

This is my code:

    from flask import Flask, request, jsonify

        app = Flask(__name__)

        @app.route('/test/', methods=['POST'])
        def msg():
            return jsonify(request.json)

Eventually I'd need to turn this into a webscraping app with Selenium, I've already written the code and everything works fine locally, but I need this final step to make it work.

Thans

What is the error?

Sorry. "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again." "curl: (6) Could not resolve host: application"

whenever I curl "http://dtaubaso.pythonanywhere.com/test" or "http://dtaubaso.pythonanywhere.com/test/"

thanks

That suggests to me that the code that you showed us above is not being executed by your web app. Make sure that the file that contains that code is being imported by your web app and that the definition of the view is not is a block of code that is being skipped for some reason (like being in an if where the condition is false)

@app.route('/test/', methods=['POST'])

should there be a trailing / after test?

all examples I have seen would be

@app.route('/test', methods=['POST'])

Both are correct depending on what you want to do. If you have the trailing slash, then you need to use it in the URL.