I am using the of request.data
to make a sqlalchemy query but running into an issue:
@app.route('/update', methods=['GET', 'POST', 'OPTIONS'])
def update_gh():
y = request.data
print(y)
# "7090364643"
x = db_session.query(Candidate).filter(Candidate.url.contains("7090364643")).first()
print(x)
# Prints the record as expected
This works. I am copying and pasting in the printed value of y
into .contains()
.
However, this isn't working:
@app.route('/update', methods=['GET', 'POST', 'OPTIONS'])
def update_gh():
y = request.data
print(type(y))
# <type 'str'>
x = db_session.query(Candidate).filter(Candidate.url.contains(y)).first()
print(x)
# None
What am I doing wrong? Why does it work when I manually input the value of y
but not when I put in the variable y
?
Update:
The request originates from a button click:
function searchDB(profile_url) {
console.log(profile_url);
$.ajax({
type: 'POST',
url:'http://127.0.0.1:5000/update_greenhouse',
data: JSON.stringify(profile_url),
contentType: "application/json"
})
}