Skip to main content

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.4.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mercari_dpop-0.0.4-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file mercari_dpop-0.0.4.tar.gz.

File metadata

  • Download URL: mercari_dpop-0.0.4.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for mercari_dpop-0.0.4.tar.gz
Algorithm Hash digest
SHA256 955490ce1399aba0bd480f7a7f85982532d44097e57b6814c3759d4ec8afaa61
MD5 067566ae1404026536c44a1c90c585cc
BLAKE2b-256 1f2fe0ca6b6204289f89dbef4e9afb218587ce775c17c14d90a65adf04617b8a

See more details on using hashes here.

File details

Details for the file mercari_dpop-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: mercari_dpop-0.0.4-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

Hashes for mercari_dpop-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9ceb41b1d869ca015811803db7fef498fad9cb48b1204fa0ecb4a893e4fd1080
MD5 e93b781a7c82f4b4ed8b58d7e66183b4
BLAKE2b-256 6d6ceca5140706f713c55e34f0713f45aceffa183abc1cbaaa88dc9943ab0c84

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page