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.6.tar.gz (6.7 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.6-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mercari_dpop-0.0.6.tar.gz
  • Upload date:
  • Size: 6.7 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.6.tar.gz
Algorithm Hash digest
SHA256 1ab1240a8141965c0498dfb34829941abb89de2edb4778b4ba33afaaba3eef0e
MD5 819cd4261cafffa69deb61307f3d87e2
BLAKE2b-256 0077f1ab3f33c2fbbad59a8e03f3a1dbad9048d739d8fb37eddf44ba24f93dab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mercari_dpop-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d10d4060386549212ddb6d6c98928dcc416649d162652f7ee1f332357351c2e4
MD5 f057f142bfb8946b9d271ab8605e16aa
BLAKE2b-256 53b403c1ecbfb04a56328dee482a2ef6d32e463bf84b4e56fd74aa2cbc59003d

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