Search code examples
pythonflaskpython-requestsflask-restplus

flask python requests post using JSON data to localhost


Iam trying to post a request using requests to my own API in localhost. The API is used to create a user. The problem is, when i try using Swagger UI, it works, but when i try using HTML form, the page always give me never ending loading.

Here is my view code:

    url = "http://localhost:5000/api/user/"
    email = request.form.get('email')
    username = request.form.get('username')
    password = request.form.get('password')
    jsondata = {
        "email": email,
        "username": username,
        "password": password
    }
    req = requests.post(url, json=jsondata)
    return redirect(url_for('main.main'))

Here is the API (Using Flask_restplus)

def post(self):
    data = api.payload
    return save_new_user(data) # store the data to database

What is wrong here? Thanks before


Solution

  • Ok, i found the answer. Flask cannot handle multiple request at once. Here is the link

    Github