首页 > 解决方案 > 当我在邮递员中将其传递给删除方法时,我得到 dict 对象没有更低的属性

问题描述

烧瓶 当我在邮递员中将其传递给删除方法时,我得到 dict 对象没有更低的属性

 def delete_package():
        try:
            data = request.json
            #converting json object to dataframe
            df = pd.DataFrame([data])
    #extracting table_name,where clause attributes and value of the where clause attributes
    table_name = df.filter(items=['table_name'],axis=1).values[0][0].lower()
    where = df.filter(items=['where'],axis=1).values[0][0].lower()
    value = df.filter(items=['value'],axis=1).values[0][0]

    #checking if the value is of string type to lower() the input else if it is of interger value will be unchanged
    if isinstance(value,str)==True:
        value = value.lower()
    args=get_args()
    connection,_,_ = get_db_connection(args,psycopg2)#module name should be user input
    status = delete_records(table_name, where, value, connection)
    
    if status == True:
        return {"status": "success", "message": 'successfully deleted'}
    else:
        return status
except Exception as err:
    return {"status": "failed", "message": 'Exception occurred- '+str(err)}

postgres.py 这是 postgres.py 的代码

def delete_records(table, unique_identifier, uniqueid, connection):#put a check if the data is present #put similar check here
    '''
        deletes record from database
        Params:
        table - tablename where deletion will occur
        unique_identifier - column associated with 'where' clause
        uniqueid - value of the column associated with where clause
        connection - database connection
    '''
    col_name_list = get_columnname_fromdb(table,connection)
    if unique_identifier in col_name_list:
        # query = ''' DELETE FROM test_docker.\"{table_name}\" where \"{column_name}\" = '{uique_id}'; '''.format(table_name=table,
        #                                                                                         column_name = unique_identifier,
        #                                                                                         uique_id = uniqueid)
        query = ''' DELETE FROM \"{table_name}\" where \"{column_name}\" = '{uique_id}'; '''.format(table_name=table,
                                                                                                column_name = unique_identifier,
                                                                                                uique_id = uniqueid)
        connection.cursor().execute(query)
        connection.commit()
        
        return True
    else:
        return ({"status": "failed", "message": 'check data for where clause. Also check the spelling'})

当我经过这个邮递员

{
    "table_name":"body_detail",
    "where":{"job_name":"tight", "help_name":"name", "condition":"hehehee"},
    "value":"True"
}

我收到错误 dict object has no attribute lower 我应该在邮递员中传递什么才能成功删除

标签: pythonpostgresqlsql-deletedelete-row

解决方案


推荐阅读