Getting cursor.close() UnboundLocalError: local variable ‘cursor’ referenced before assignment error while calling /api/view/addmin

Solution
def token_required(f):
    @wraps(f)
    def decorated(*args,**kwargs):
        token= None
        if 'x-acess-token' in request.headers:
            token=request.headers['x-acess-token']
        if not  token:
            return  jsonify("token not found")
            
        conn=mysql.connect()
        cursor=conn.cursor(pymysql.cursors.DictCursor)
        try:
            data=jwt.decode(token,app.config['SECRET_KEY'])
            cursor.execute('select  * from hireme_emp  where id=%s LIMIT 1',(data['public_id'],))
            current_user=cursor.fetchone()
        except:
            return jsonify('invalid token')
        finally:
            cursor.close()
            conn.close()
        return  f(current_user,*args,**kwargs)
    return decorated