Python编码为“def create”可以接受除&#”以外的符号

2024-09-26 22:08:14 发布

您现在位置:Python中文网/ 问答频道 /正文

对不起,我在Odoo 8中创建了def供API使用。可以保存或创建包含符号的任何字符。 enter image description here

使用这样的编码:

def create(self, cr, uid, vals, context=None):
    print 'create assign'

    wo_name = ''
    if vals.get('name'):
        print(vals.get('name'))

        wo_name = str(vals.get('name'))
        self.wo_name_duplicate(cr, uid, wo_name, context=None)

    assign_d = super(amtiss_assignment, self).create(cr, uid, vals, context=context)
    assign_h = self.browse(cr, uid ,assign_d)

    print assign_d
    print vals.get('asset_id')

    assignment_obj = self.pool.get('amtiss.assignment_line')

    url = "https://fcm.googleapis.com/fcm/send"
    headers = {
    'Authorization': 'key=AAAAfPDihpA:APA91bFcajfoF85Qi_kmgeKRMbGLKvCaJVGuJt9wbWGpBsUDcNk9H6TG6xNIfBGuoJizsIhgwiAfQg7SRnx0FUrDMFikMAChgoMVKH_ChOUSt7O-LlDGYr00yENOlMUW8E1ZA2UHQChD',
    'Content-Type': 'application/json'
    }
    bbas = str(cr.dbname)
    wo_not = ''

    assignment_obj.create(cr, uid, {'assign_id': assign_d, 'id_asset': vals.get('asset_id')}, context=None)

    location_push = ''
    l = str(assign_h.asset_id.location_id.name)
    text = str(bbas + l).encode('utf-8')
    hash_md5 = hashlib.md5(text).hexdigest()
    md5_encode = hash_md5.encode('utf-8')
    hash_sha1 = hashlib.sha1(md5_encode).hexdigest()
    location_push = hash_sha1[0:6]
    
    if self.pool['res.users'].has_group(cr, uid, 'amtiss_notification.group_amts_push_notif_maintenance'):
        m = '_group_amts_push_notif_maintenance'
        text = str(bbas + m).encode('utf-8')
        hash_md5 = hashlib.md5(text).hexdigest()
        md5_encode = hash_md5.encode('utf-8')
        hash_sha1 = hashlib.sha1(md5_encode).hexdigest()
        wo_not = hash_sha1[0:6]

        form_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'amtiss', 'amtiss_assignment_action_menu')[1]
        ac_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'amtiss', 'action_amtiss_assignment')[1]
        urls = http.request.env['ir.config_parameter'].get_param('web.base.url')
        print form_id
        print ac_id
        print urls
        url_comp = str(urls) + '/web#id=' + str(assign_d) + '&view_type=form&model=amtiss.assignment'

        payload = '''{ \"condition\" : \"'%s' in topics && '%s' in topics && 'wbamtiss' in topics\", \"collapse_key\" : \"type_a\",
        \"notification\" : {     \"body\" : \"%s - Work Order - %s - %s\",     \"title\": \"%s(%s) has been created\",     \"click_action\": \"%s\" },
        \"data\" : {\"title\" : \"Work Order\", \"subtitle\" : \"%s\", \"location\": \"%s\", \"date\": \"%s\", \"user\": \"%s\", \"user_id\": "%s\" }
        }'''%(str(wo_not),str(location_push),str(assign_h.create_date),str(assign_h.create_uid.name),str(assign_h.asset_id.name),str(vals.get('name')),str(assign_h.asset_id.location_id.name),str(url_comp),str(vals.get('name')),str(assign_h.asset_id.location_id.name),str(assign_h.create_date),str(assign_h.create_uid.name),str(assign_h.create_uid.id))
        
        response = requests.request("POST", url, headers=headers, data = payload)

        url_comp = 'NEWSFEEDACTIVITY'
        payload = '''{ \"condition\" : \"'%s' in topics && '%s' in topics && 'mbamtiss' in topics\", \"collapse_key\" : \"type_a\",
        \"notification\" : {     \"body\" : \"%s - Work Order - %s - %s\",     \"title\": \"%s(%s) has been created\",     \"click_action\": \"%s\" },
        \"data\" : {\"title\" : \"Work Order\", \"subtitle\" : \"%s\", \"location\": \"%s\", \"date\": \"%s\", \"user\": \"%s\", \"user_id\": "%s\" }
        }'''%(str(wo_not),str(location_push),str(assign_h.create_date),str(assign_h.create_uid.name),str(assign_h.asset_id.name),str(vals.get('name')),str(assign_h.asset_id.location_id.name),str(url_comp),str(vals.get('name')),str(assign_h.asset_id.location_id.name),str(assign_h.create_date),str(assign_h.create_uid.name),str(assign_h.create_uid.id))
        
        response = requests.request("POST", url, headers=headers, data = payload)
    
    return assign_d

除了这些符号&;#' enter image description hereenter image description here

如何修复解析数据以接受符号的代码

问候,, 福齐


Tags: nameselfiduidgetcreatelocationasset

热门问题