Issue
I try to generate the signature (sign) by python code below with several times of edition but always get the wrong sign, would be really appreciate if someone could help with this:
import hashlib
import json
import requests
nick = ['奇思种子']
key = 'd0da37aaab474d0195cf649c889f8d34'
param = {"method":"gy.erp.shop.get","appkey":"114888","sessionkey":"3fa8000e6e844a5d865c27d4e7e1175c","page_size":"100"}
# param['nick'] = str(nick[0].encode('utf-8'))
param['nick'] = str(nick[0])
pjson = json.dumps(param)
postdata = {'param': pjson }
str1 = key + pjson + key
str2 = str1.replace(": ", ":")
str3 = str2.replace(", ", ",")
md = hashlib.md5()
md.update(str3.encode())
sign = md.hexdigest().upper()
param["sign"] = sign
pjson2 = json.dumps(param)
str_2 = pjson2.replace(": ", ":")
str_3 = str_2.replace(", ", ",")
Solution
You have to set ensure_ascii
attribute to False.
import hashlib
import json
import requests
nick = ['奇思种子']
key = 'd0da37aaab474d0195cf649c889f8d34'
param = {"method":"gy.erp.shop.get","appkey":"114888","sessionkey":"3fa8000e6e844a5d865c27d4e7e1175c","page_size":"100"}
# param['nick'] = str(nick[0].encode('utf-8'))
param['nick'] = str(nick[0])
pjson = json.dumps(param, ensure_ascii=False)
postdata = {'param': pjson }
str1 = key + pjson + key
str2 = str1.replace(": ", ":")
str3 = str2.replace(", ", ",")
md = hashlib.md5()
md.update(str3.encode('utf-8'))
sign = md.hexdigest().upper()
param["sign"] = sign
pjson2 = json.dumps(param)
str_2 = pjson2.replace(": ", ":")
str_3 = str_2.replace(", ", ",")
Answered By - Harshana Serasinghe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.