I adjust the payment on the site through interkassu. Interkassa after successful payment by the user, sends a notification of payment to the server. The signature is formed by gluing all the request fields and pasting the secret key to the end, followed by encoding in md5 or sha256 into a byte-array. The form:

<input type="hidden" name="ik_am" value="1.00"> <input type="hidden" name="ik_act" value="process"> <input type="hidden" name="ik_co_id" value="571624f33d1eafb1528b456b"> <input type="hidden" name="ik_co_prs_id" value="307447812424"> <input type="hidden" name="ik_co_rfn" value="0.94"> <input type="hidden" name="ik_cur" value="RUB"> <input type="hidden" name="ik_desc" value="Оплата товара"> <input type="hidden" name="ik_inv_crt" value="2013-03-17 17:35:33"> <input type="hidden" name="ik_inv_id" value="5632156"> <input type="hidden" name="ik_inv_prc" value="2013-03-17 17:36:13"> <input type="hidden" name="ik_inv_st" value="success"> <input type="hidden" name="ik_pm_no" value="70"> <input type="hidden" name="ik_ps_price" value="20"> <input type="hidden" name="ik_pw_via" value="yandex"> <input type="hidden" name="ik_trn_id" value="14533"> <input type="hidden" name="ik_sign" value="oVAOevI3mWrcvrjB4j/ySg=="> 
 variables = "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s" % ( form.cleaned_data['ik_am'], form.cleaned_data['ik_act'], form.cleaned_data['ik_co_id'], form.cleaned_data['ik_co_prs_id'], form.cleaned_data['ik_co_rfn'], form.cleaned_data['ik_cur'], form.cleaned_data['ik_desc'], form.cleaned_data['ik_inv_crt'], form.cleaned_data['ik_inv_id'], form.cleaned_data['ik_inv_prc'], form.cleaned_data['ik_inv_st'], form.cleaned_data['ik_pm_no'], form.cleaned_data['ik_ps_price'], form.cleaned_data['ik_pw_via'], form.cleaned_data['ik_trn_id'] ) 

For pasting, I use hash_key = md5(variables.encode('utf-8')).digest() for hashing. But I get the error:

'ascii' codec can't decode byte 0xeb in position 0: ordinal not in range (128)

Help solve the problem.

  • The question is to add, then it will most likely be answered. It would be nice to add an example of variables - form.cleaned_data and variables . The code itself, which turns all this, would not hurt either. - Lebedev Ilya

1 answer 1

Since at the beginning of the code you do not use the u prefix before double quotes, and you have this error, it means you are using Python2. You need to specify it in order for Python to understand that you are building a unicode string. The code given by you is written a little suboptimally and I would rewrite it like this:

 keys = 'am,act,co_id,co_prs_id,co_rfn,cur,desc,inv_crt,'\ 'inv_id,inv_prc,inv_st,pm_no,ps_price,pw_via,trn_id' variables = u':'.join(unicode(form.cleaned_data['ik_'+k]) for k in keys.split(',')) hash_key = md5(variables.encode('utf-8')).digest()