Это простое приложение, которое вставляет данные в mysql db. Данные вставлены правильно, но я не получаю ответ на свой почтовый запрос, но статус - 200.request.form работает, но я хочу отправить json в качестве полезной нагрузки. Это мой маршрут ниже, и я считаю, что что-то не так, когда я проверка наличия ключей в моей полезной нагрузке json. Я пробовал использовать request. json, request.get_ json, request.get_ json (), но я не могу избавиться от этой ошибки, хотя статус равен 200, но приложение не возвращает никакого сообщения.
@app.route('/pythonlogin/register', methods=['GET', 'POST'])
def register():
# Output message if something goes wrong..
msg = ''
# current_time = time.strftime('%Y-%m-%d %H:%M:%S')
# Check if "username", "password" and "email" POST requests exist (user submitted form)
if request.method == 'POST' and request.get_json().get('name') != None and request.get_json().get('password') != None and request.get_json().get('email') != None and request.get_json().get('size')!= None :
data = request.get_json().get
# Create variables for easy access
name = data('name')
password = data('password')
email = data('email')
size = data('size')
# Check if account exists using MySQL
cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute('SELECT * FROM user WHERE email = %s', (email,))
account = cursor.fetchone()
print(account)
# If account exists show error and validation checks
if account:
msg = 'Account already exists!'
elif not re.match(r'[^@]+@[^@]+\.[^@]+', email):
msg = 'Invalid email address!'
elif not re.match(r'[A-Za-z0-9]+', name):
msg = 'Username must contain only characters and numbers!'
elif not re.match(r'[0-9]',size):
msg = 'Team size accepts only numbers'
elif not name or not password or not email or not size:
msg = 'Please fill out the form!'
else:
print('inside else')
role = 1
# Account doesnt exists and the form data is valid, now insert new account into accounts table
cursor.execute('INSERT INTO company VALUES (NULL, %s,NULL, %s, %s)', (name, size,current_time))
#cursor.execute('INSERT INTO user VALUES (NULL, %s, %s, NULL,NULL, NULL,NULL, NULL,NULL, NULL)', (email, password,))
mysql.connection.commit()
cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute('SELECT * FROM company WHERE name = %s ' ,(name,))
results = cursor.fetchone()
comp_id = results['company_id']
cursor.execute('INSERT INTO user VALUES (NULL, NULL, %s,%s, %s,NULL, NULL,NULL, %s,%s)', (email, password,role,current_time,comp_id,))
mysql.connection.commit()
msg = 'You have successfully registered!'
else :
# Form is empty... (no POST data)
msg = 'Please fill out the form!'
return {"status":"1","message":msg}
это мой ответ ниже:
Debugging middleware caught exception in streamed response at a point where response headers were already sent
и это
MySQLdb._exceptions.OperationalError: (2006, '').