diff --git a/src/xhshow/client.py b/src/xhshow/client.py index 139881f..a44d1c0 100644 --- a/src/xhshow/client.py +++ b/src/xhshow/client.py @@ -1,6 +1,7 @@ import hashlib import json import time +import urllib.parse from typing import Any, Literal from .config import CryptoConfig @@ -46,12 +47,18 @@ def _build_content_string(self, method: str, uri: str, payload: dict[str, Any] | if not payload: return uri else: - # XHS signature algorithm requires only '=' to be encoded as '%3D', - # other characters (including ',') should remain unencoded - params = [ - f"{key}={(','.join(str(v) for v in value) if isinstance(value, list | tuple) else (str(value) if value is not None else '')).replace('=', '%3D')}" # noqa: E501 - for key, value in payload.items() - ] + params = [] + for key, value in payload.items(): + if isinstance(value, list | tuple): + value_str = ",".join(str(v) for v in value) + elif value is not None: + value_str = str(value) + else: + value_str = "" + + encoded_value = urllib.parse.quote(value_str, safe=",") + params.append(f"{key}={encoded_value}") + return f"{uri}?{'&'.join(params)}" def _generate_d_value(self, content: str) -> str: