I have this php function that i'm in front of developping the same in python 2.7:
//PHP
$actionSLK = 'https://test.monsite.com/script.cgi';
$storeId = 'test';
$cartId = 'test2';
$totalAmountTx = '100';
$email = 'test@monsite.com';
$SLKSecretKey = 'secret';
$dataMD5=$actionSLK . $storeId . $cartId . $totalAmountTx . $email . $SLKSecretKey
$checksum=MD5(utf8entities(rawurlencode($dataMD5)));
#PYTHON:
from hashlib import md5
import urllib
actionSLK = 'https://test.monsite.com/script.cgi'
storeId = 'test'
cartId = 'test2'
totalAmountTx = '100'
email = 'test@monsite.com'
SLKSecretKey = 'secret'
dataMD5 = actionSLK + storeId + cartId + totalAmountTx + email + SLKSecretKey
checksum = md5(urllib.quote(dataMD5).encode('utf8')).hexdigest()
The problem that i found is the calculated checksum is not the same MD5
, and then i have checked the encoded url (generated one: 'https://test.monsite.com/script.cgitesttest100test@monsite.comsecret'
), and here we are:
//PHP
$checksum=MD5('https%3A%2F%2Ftest.monsite.com%2Fscript.cgitesttest100test%40monsite.comsecret');
#PYTHON
checksum = md5('https%3A//test.monsite.com/script.cgitesttest100test%40monsite.comsecret').hexdigest()
So the slash is not encoded so an error will be occured when generating differents checksum.
is there an other function in urllib that encode urls like this one in the detail ?