针对 AkShare 和 efinance 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
Project description
AkShare Proxy Patch
针对 akshare 和 efinance 的插件补丁,自动为接口注入请求头,解决 stock_zh_a_spot_em、stock_zh_a_hist、get_realtime_quotes 等东财接口报错问题。
安装
pip install akshare-proxy-patch==0.2.13
使用方法
akshare 和 efinance 使用方式一致,在文件顶部添加2行代码即可,无需其他额外操作。
# python 文件顶部添加如下代码
import akshare_proxy_patch
akshare_proxy_patch.install_patch(
"101.201.173.125",
auth_token="",
retry=30,
hook_domains=[
"fund.eastmoney.com",
"push2.eastmoney.com",
"push2his.eastmoney.com",
"emweb.securities.eastmoney.com",
],
)
# 后续你的正常业务代码保持不变
# 假如你使用 akshare
import akshare as ak
df = ak.stock_zh_a_spot_em()
# 假如你使用 efinance
import efinance as ef
ef.stock.get_realtime_quotes()
install_patch 参数说明
- 参数1:网关
- 默认为
101.201.173.125不可修改
- 默认为
- 参数2:TOKEN
- 默认为空,每天可免费使用一定次数。如有更多需求,可点击此处注册申请正式的
TOKEN。
- 默认为空,每天可免费使用一定次数。如有更多需求,可点击此处注册申请正式的
- 参数3:重试次数
- 默认为30,建议保持不变
- 参数4:需要hook的域名列表
- 接口URL包含列表内任意一条域名都会走代理,可以根据封控情况调整或细化以降低积分消耗
- 如只封控
stock_zh_a_spot_em这个接口,hook_domains=["https://82.push2.eastmoney.com/api/qt/clist/get"] 即可(点击函数查看接口源码找到对应域名)
如何在 aktools 内集成插件?
需要新建一个 akt.py 替换官方的启动方式:
# 添加插件
import akshare_proxy_patch
akshare_proxy_patch.install_patch(
"101.201.173.125",
auth_token="",
retry=30,
hook_domains=[
"fund.eastmoney.com",
"push2.eastmoney.com",
"push2his.eastmoney.com",
"emweb.securities.eastmoney.com",
],
)
# 启动 aktools
import uvicorn
if __name__ == '__main__':
uvicorn.run(
"aktools.main:app",
host="0.0.0.0",
port=8080,
reload=False,
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
workers=4,
log_level="info"
)
然后执行 python akt.py 即可启动并正常使用 aktools。
我是手动爬取的接口,能集成插件吗?
能。如果您没有使用 akshare 或 efinance,而是手动调用的接口,只要代码是使用的 requests,插件都能 hook 住请求,正常工作。
使用问题交流群
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
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
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