mipu-requests
米普代理 HTTP 客户端,兼容 requests 接口。
所有 HTTP 请求通过米普 API 转发,接口与 requests 完全一致,迁移只需改 import 和 proxies。
安装
pip install mipu-requests
快速开始
import mipu_requests
s = mipu_requests.session(
base_url="https://api-eu.mipuyun.com",
client_key="your_client_key",
client_secret="your_client_secret",
agent="JQ",
)
s.proxies = "res_mipu_bookxWdyg"
resp = s.get("https://example.com/page")
resp.raise_for_status()
data = resp.json()
从 requests 迁移
# ── 迁移前 ──────────────────────────
import requests
s = requests.Session()
s.proxies = {"https": "http://proxy:8080"}
resp = s.get("https://example.com/api")
# ── 迁移后 ──────────────────────────
import mipu_requests
s = mipu_requests.session(
base_url="https://api-eu.mipuyun.com",
client_key="your_key",
client_secret="your_secret",
agent="JQ",
)
s.proxies = "res_mipu_bookxWdyg"
resp = s.get("https://example.com/api")
只需两步:
import requests→import mipu_requests- 构造时传入凭据,
proxies改为字符串
其余代码(.get(), .post(), .json(), .raise_for_status() 等)无需改动。
请求方法
resp = s.get(url, params={"key": "value"}, headers={...})
resp = s.post(url, data={"key": "value"}, headers={...})
resp = s.post(url, json={"key": "value"}, headers={...})
resp = s.put(url, data=body, headers={...})
resp = s.delete(url, headers={...})
异步模式
默认启用异步轮询,防止长连接断连:
# 默认异步
s = mipu_requests.session(..., async_mode=True)
# 关闭异步
s = mipu_requests.session(..., async_mode=False)
# 自定义轮询参数
s = mipu_requests.session(
...,
poll_interval=3, # 轮询间隔(秒)
poll_max=20, # 最大轮询次数
submit_timeout=60, # 提交超时(秒)
poll_timeout=(5, 30), # 轮询超时 (connect, read)
)
Response 对象
与 requests.Response 完全兼容:
resp.status_code # int HTTP 状态码
resp.text # str 响应体文本
resp.content # bytes 响应体字节
resp.headers # dict 响应头
resp.ok # bool status_code 在 200-399
resp.url # str 请求 URL
resp.json() # dict 解析 JSON
resp.raise_for_status() # >=400 抛异常
异常处理
from mipu_requests import RequestException, HTTPError, APIError, PollTimeoutError
try:
resp = s.get(url)
resp.raise_for_status()
except HTTPError as e:
print(f"目标站错误: {e.response.status_code}")
except APIError as e:
print(f"API 错误: {e}")
except PollTimeoutError as e:
print(f"轮询超时: {e}")
except RequestException as e:
print(f"请求异常: {e}")
License
MIT
Metadata
Release files for mipu-requests 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mipu_requests-1.0.2.tar.gz | 8.2 kB | Without provenance | Details for mipu_requests-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mipu_requests-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for mipu_requests-1.0.2-py3-none-any.whl |
Total release size: 17.6 kB
Release files / mipu_requests-1.0.2.tar.gz
| Download URL | mipu_requests-1.0.2.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9aacd099c616939a4b375cd20235aa3b248fdd233ab3b36629e8b4809a21cf30
|
|
BLAKE2b-256 checksum How to use checksums |
311cbff9113c5211ab98be725dee283dd90cc6270fa4385426f0082f678f4ec4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Release files / mipu_requests-1.0.2-py3-none-any.whl
| Download URL | mipu_requests-1.0.2-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e146d095866979548de989d132672309550c6746050595ab11f9ab3a2dd08900
|
|
BLAKE2b-256 checksum How to use checksums |
cc06a8ab55f468cd9fb3f6d0ac20dec7c8d72ec5c5855c9f71af299a8de1599e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Security for mipu-requests 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.