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