admin管理员组文章数量:1122832
I am making a react native app with a python flask backend. I am providing directions to my user based on the terminal value from a form submitted by the user. For some reason, in the very first form submitted when opening the app the terminal value is set as NoneType, giving me the error: "can only concatenate str (not "NoneType") to str" but for every form submitted after that the value of terminal corresponds correctly to the value submitted and the correct directions are given.
@app.route('/directions', methods = ['GET', 'POST'])
def get_terminal_directions():
if request.method == 'POST':
form_data = request.json
terminal = form_data['terminal']
session['terminal'] = terminal
terminal = session.get('terminal')
print('Session' + session.get('terminal'))
_, location_data = get_location()
#latitude = data['location']['lat']
#longitude = data['location']['lng']
latitude = 41.97750594826151
longitude = -87.9055705049776
# destination = quote(f"Terminal:, O'Hare International Airport")
destination = "Terminal:" + terminal + "O'Hare International Airport"
DIRECTIONS_URL = f'={destination}&origin={latitude},{longitude}&mode=walking&key=AIzaSyDaTHaEQ1jwYb-FZSwk-NVJgP9c0PzjS7E'
try:
headers = {
'Content-Type': 'application/json'
}
response = requests.get(
DIRECTIONS_URL,
headers=headers,
)
if response.status_code == 200:
data = response.json()
print('after' + terminal)
return data
else:
error_message = response.json().get('error', {}).get('message', 'Unknown error')
return jsonify({
"error": f"Google Directions API error: {error_message}"
}), response.status_code
except Exception as e:
return jsonify({
"error": str(e)
}), 500
本文标签: pythonUse flask sessions to utilize data obtained from POST request in a GET requestStack Overflow
版权声明:本文标题:python - Use flask sessions to utilize data obtained from POST request in a GET request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283561a1927008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论