Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def delete_author():
"""Add an author."""
if request.headers['Content-Type'] != 'application/json':
current_app.logger.debug(request.headers['Content-Type'])
return jsonify(msg=_('Header Error'))
data = request.get_json()
indexer = RecordIndexer()
indexer.client.delete(id=json.loads(json.dumps(data))["Id"],
index="authors",
doc_type="author",)
with db.session.begin_nested():
author_data = Authors.query.filter_by(id=json.loads(json.dumps(data))["pk_id"]).one()
db.session.delete(author_data)
db.session.commit()
return jsonify(msg=_('Success'))
def post(self):
json_data = request.get_json()
if not json_data:
return {"message": "Must provide message to send to slack"}, 400
try:
slack_message = json_data['slack_message']
except KeyError as err:
return {"message": "Must provide message to send to slack"}, 422
print(slack_message)
slack_json_data = {
"text": slack_message
}
print(slack_json_data)
params = json.dumps(slack_json_data).encode('utf8')
Ejemplo::
>>> curl -X POST -d "tipo=Alumno&idEntidad=3242&nombreEntidad=alumnoNuevo" localhost:8003/entidadesReferencia
{'status': 'OK', 'idEntidad': '5'}
>>> res = requests.post('localhost:8003/entidadesReferencia', data={ 'tipo': 'Profesor', 'idEntidad': 3135, 'nombreEntidad': 'nombreProfesor' })
>>> jsonpickle.decode(res.text)
{'status': 'OK', 'idEntidad': '5'}
"""
if v:
print nombreMicroservicio
print ' Llamando a /entidadesReferencia POST insertarEntidad()'
print " Request: "
print request.form
data = request.get_json()
print data
return jsonpickle.encode(Gestor.insertarEntidad(data['tipo'], int(data['idEntidad']), data['nombreEntidad']))
def unique():
try:
request_dict = request.get_json()
jsonstr = request_dict['jsonStr']
df = pd.read_json(json.dumps(eval(jsonstr)), orient='split')
dataframe_nunique = df.nunique()
values = dataframe_nunique.values.tolist()
keys = dataframe_nunique.index.values.tolist()
nunique_dict = dict(zip(keys, values))
response = app.response_class(
response=json.dumps(nunique_dict),
status=200,
mimetype='application/json'
)
except:
exception = ExceptionHelpers.format_exception(sys.exc_info())
response = app.response_class(
response=exception,
status=400,
def StartGame():
data = request.get_json()
if data['admin_password'] != ADMIN_PASSWORD:
return GetResp((200, {"msg":"Fail"}))
softRestart = False
if "soft" in data and data["soft"] == True:
softRestart = True
if "ai_only" in data and data["ai_only"] == True:
aiOnly = True
else:
aiOnly = False
width = 30
height = 30
global globalGameWidth
global globalGameHeight
globalGameWidth = width
globalGameHeight = height
def validateHash():
digest = request.get_json().get('hash')
if digest is None:
return "Error: no hash provided", 400
if (blockchain.block_hash(blockchain.lastBlock) == digest):
return "Success: Current hash is valid", 200
else:
# forward new block to other nodes for validation
chainLen = len(blockchain.chain)
newBlock = blockchain.create_block(digest)
data = {
'nodeID': blockchain.nodeid,
'block': newBlock
}
blockchain.sendToNodes('/chain/pre-prepare', data)
if (len(blockchain.chain) > chainLen):
def decorated(instance, *args, **kwargs):
"""The decorator function."""
data = request.get_json(force=True, silent=True)
if not data:
raise BadRequestException('No data received from request')
for key in data:
if key not in (
instance.__model__.required() +
instance.__model__.optional()):
raise BadRequestException('Unknown field [{}]'.format(key))
missing = set(instance.__model__.required()) - set(data)
if missing:
message = 'The following required fields are missing: ' + ', '.join(missing)
raise BadRequestException(message)
return func(instance, *args, **kwargs)
return decorated
def changePassword():
try:
data = request.get_json()
except Exception:
return ErrorResponse(PayloadNotFound().message, 422, {'Content-Type': 'application/json'}).respond()
if data and data['username']:
user = User.getUser(username=data['username'])
if user:
if not verifyPassword(user, data['password']):
return ErrorResponse(PasswordNotFound().message, 422, {'Content-Type': 'application/json'}).respond()
user.password = generate_password_hash(data['newPassword'])
try:
user.save_to_db()
except Exception:
return ErrorResponse(OperationNotFound().message, 422, {'Content-Type': 'application/json'}).respond()
return jsonify(
def oauth_token():
try:
data = request.get_json()
except Exception:
return ErrorResponse(PayloadNotFound().message, 422, {'Content-Type': 'application/json'}).respond()
try:
token = jwt.encode(
{'user': data.get('username')},
app.config.get('SECRET_KEY'))
except Exception:
return ErrorResponse(OperationNotFound().message, 422, {'Content-Type': 'application/json'}).respond()
return jsonify(
Response(200).generateToken(
token.decode('UTF-8')))
def upload():
if request.method == 'GET':
if not current_user.is_authenticated:
flash('You must log in first to upload kifus')
return redirect(url_for('index'))
return render_template('upload.html')
# request.method == 'POST'
# validate SGF and get SGF info
kifu_json = request.get_json()
print(kifu_json)
if not validate_sgf(kifu_json['sgf']):
abort(400)
info = get_sgf_info(kifu_json['sgf'])
sgf_str = standardize_sgf(kifu_json['sgf'])
# insert kifu into database
kifu = Kifu(
title=kifu_json['title'],
description=kifu_json['description'],
black_player=info['PB'],
white_player=info['PW'],
black_rank=info['BR'],
white_rank=info['WR'],
komi=info['KM'],
result=info['RE'],