S
S
Sasha Savvov2021-10-05 09:11:53
Python
Sasha Savvov, 2021-10-05 09:11:53

How to properly handle outgoing B24 webhook data in python?

The python application processes the outgoing Bitrix24 webhook.

From request.form I get a dictionary of such key-value pairs: { '
data[PARAMS][CHAT_ENTITY_DATA_1]' : '...'

}
CHAT_ENTITY_DATA_1' : '...' } } }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor T2, 2021-10-05
@savvov

eval is:

import ast

inpt =  { 'data[PARAMS][CHAT_ENTITY_DATA_1]' : '...' ,
        'data[PARAMS][CHAT_ENTITY_DATA_2]' : '...'  ,
        'data[PARAMS][CHAT_ENTITY_DATA_3]' : '...'  }

results = []

for k, v in inpt.items():
    print(k,v)
    # корячим входную строку как нам нужно:
    r_str = "{'" + k.replace("[","':{'").replace("]","") + "':'" + v + "'}}}"
    print('строка ', r_str)
    print(type(r_str))
    # с помощью eval превращаем строку в словарь: 
    r = ast.literal_eval(r_str)
    print('словарь ', r_str)
    print(type(r))
    
    results.append(r)
    
print('\nрезультат\n', results)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question