[Python] Shopee API sandbox: error_sign even with correct Test Partner ID and Partner Key

Discussão em 'Python' iniciado por Stack, Agosto 31, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to integrate with the Shopee Partner API (sandbox environment), but I always get an error_sign response even though I’m using my Test Partner ID and Test API Partner Key from the developer console.

    Link to the documentation: https://open.shopee.com/developer-guide/20

    currently the redirect link just an example but it should able to get the expected parameter from the response url.

    import hmac
    import json
    import time
    import requests
    import hashlib


    def shop_auth():
    timest = int(time.time())
    host = "https://partner.test-stable.shopeemobile.com"
    path = "/api/v2/shop/auth_partner"
    redirect_url = "https://www.baidu.com/"
    partner_id = 117...
    tmp = "shpk7262645a54484f5375737a427378534a4f74715449414f..."
    partner_key = tmp.encode()
    tmp_base_string = "%s%s%s" % (partner_id, path, timest)
    base_string = tmp_base_string.encode()
    print("base String:"+tmp_base_string)
    sign = hmac.new(partner_key, base_string, hashlib.sha256).hexdigest()
    ##generate api
    url = host + path + "?partner_id=%s&timestamp=%s&sign=%s&redirect=%s" % (partner_id, timest, sign, redirect_url)
    print(url)

    shop_auth()


    Here is the response from what I get:

    example what the code generate: https://partner.test-stable.shopeemobile.com/api/v2/shop/auth_partner?partner_id=117...&timestamp=1756625875&sign=dd0ee43c2cfe58ca4b75758a62892809e83b8300b129d1cf9be64a27f51559ae&redirect=https://www.baidu.com/

    Response: {"error":"error_sign","message":"Wrong sign.","request_id":"e3e3e7f33da4557d60e9389bfe89dc01"}

    As I go through some of the old post, I notice their partner_key do not start with the shpk, so im not sure if I still need to do some filter to the key?

    Else I not sure what I have missed to generate the correct sign for the url.

    Continue reading...

Compartilhe esta Página