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.5.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.5-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mercari_dpop-0.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 7ad4d0e99b61ef19d9cb8284b6dde00c8f7f623a85aca78d7fc818110b1ef528
MD5 88608b1f4895887f5f7e9097ab74ecf6
BLAKE2b-256 f69d983d0fe7060a26d19c81a89843c4b165e981bfa161c61d7c72ed0ee4e0c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mercari_dpop-0.0.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 26fd2491373e723d3a094bd996d7260d0d225c7015098c70202dc69fc9e00f6a
MD5 6fdf0b0c10c8df65aae5c5ddf636305b
BLAKE2b-256 2c0ab2f6546ae049cbc35a459128a2340c7b5bceb48d2107a825923dbe3a393f

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