mercari dpop 加密参数
Project description
mercari_dpop
Mercari DPOP 加密参数生成与店铺信息查询工具库。
安装
pip install mercari_dpop
功能介绍
1. 生成 DPOP JWT — generate_dpop_jwt
根据 RFC 9449 标准,使用 ES256 (P-256) 签名算法生成 DPOP Proof JWT。
函数签名
from mercari_dpop import generate_dpop_jwt
generate_dpop_jwt(user_uuid, http_method, url) -> str
| 参数 | 类型 | 说明 |
|---|---|---|
user_uuid |
str |
用户唯一标识,通常为 str(uuid.uuid4()) |
http_method |
str |
HTTP 请求方法,如 'GET', 'POST' 等 |
url |
str |
请求的目标 URL |
返回值
返回一个 DPOP JWT 字符串(header.payload.signature 格式),可直接放入请求头的 dpop 字段。
示例
import uuid
from mercari_dpop import generate_dpop_jwt
url = "https://api.mercari.jp/users/get_profile"
dpop_token = generate_dpop_jwt(str(uuid.uuid4()), 'GET', url)
print(dpop_token)
# 使用时放入请求头
import requests
headers = {
"dpop": dpop_token,
# ... 其他 headers
}
requests.get(url, headers=headers)
2. 查看账号信息 — get_shop_info
通过 Mercari API 查询指定店铺/用户的公开资料信息,自动处理 DPOP 签名。
函数签名
from mercari_dpop import get_shop_info
get_shop_info(shop_id) -> dict
| 参数 | 类型 | 说明 |
|---|---|---|
shop_id |
str / int |
Mercari 店铺或用户 ID |
返回值
| 场景 | 返回结构 |
|---|---|
| 正常获取 | {'code': None, 'msg': None, ... 店铺详细信息} 或直接返回 data 字典内容 |
| 账号被限制 | {'code': 2, 'msg': '账号被限制'} |
| 请求失败 | {'code': 1, 'msg': 错误信息} |
示例
from mercari_dpop import get_shop_info
result = get_shop_info("914211704")
print(result)
完整示例
from mercari_dpop import generate_dpop_jwt, get_shop_info
import uuid
# 方式一:单独生成 DPOP Token
dpop = generate_dpop_jwt(str(uuid.uuid4()), 'GET', 'https://api.mercari.jp/users/get_profile')
print(f"DPOP JWT: {dpop}")
# 方式二:直接查询店铺信息
info = get_shop_info("914211704")
print(f"店铺信息: {info}")
依赖
- Python >= 3.9
- requests >= 2.33.1
- cryptography >= 47.0.0
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mercari_dpop-0.0.3.tar.gz
(5.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mercari_dpop-0.0.3.tar.gz.
File metadata
- Download URL: mercari_dpop-0.0.3.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82d67054104eb0b76ca27c0ce0f6edd3ff975b189c908d033a256a909ac919aa
|
|
| MD5 |
7974ca27620044496145af11a02bd370
|
|
| BLAKE2b-256 |
8d6887bab88161d60276f153f0e5beec53860867a827eb5372db9bf2158116eb
|
File details
Details for the file mercari_dpop-0.0.3-py3-none-any.whl.
File metadata
- Download URL: mercari_dpop-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f69de894c4f34f8c79b4f5a0e920e08eb6065a24937d22fdc4a584418e216ba2
|
|
| MD5 |
79023ee6bdf35020dd91ca4f749ad9c2
|
|
| BLAKE2b-256 |
b32c205a7141c02a1015458da0d218929957d40990940136e643fd3456ab7305
|