akshare-proxy-patch 0.2.13__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of akshare-proxy-patch might be problematic. Click here for more details.
- akshare_proxy_patch-0.4.0/PKG-INFO +159 -0
- akshare_proxy_patch-0.4.0/README.md +138 -0
- akshare_proxy_patch-0.4.0/akshare_proxy_patch/__init__.py +182 -0
- akshare_proxy_patch-0.2.13/akshare_proxy_patch/__init__.py → akshare_proxy_patch-0.4.0/akshare_proxy_patch/yfinance.py +16 -33
- akshare_proxy_patch-0.4.0/akshare_proxy_patch.egg-info/PKG-INFO +159 -0
- {akshare_proxy_patch-0.2.13 → akshare_proxy_patch-0.4.0}/akshare_proxy_patch.egg-info/SOURCES.txt +1 -0
- akshare_proxy_patch-0.4.0/akshare_proxy_patch.egg-info/requires.txt +2 -0
- {akshare_proxy_patch-0.2.13 → akshare_proxy_patch-0.4.0}/pyproject.toml +2 -1
- {akshare_proxy_patch-0.2.13 → akshare_proxy_patch-0.4.0}/setup.py +1 -1
- akshare_proxy_patch-0.2.13/PKG-INFO +0 -124
- akshare_proxy_patch-0.2.13/README.md +0 -104
- akshare_proxy_patch-0.2.13/akshare_proxy_patch.egg-info/PKG-INFO +0 -124
- akshare_proxy_patch-0.2.13/akshare_proxy_patch.egg-info/requires.txt +0 -1
- {akshare_proxy_patch-0.2.13 → akshare_proxy_patch-0.4.0}/LICENSE +0 -0
- {akshare_proxy_patch-0.2.13 → akshare_proxy_patch-0.4.0}/akshare_proxy_patch.egg-info/dependency_links.txt +0 -0
- {akshare_proxy_patch-0.2.13 → akshare_proxy_patch-0.4.0}/akshare_proxy_patch.egg-info/top_level.txt +0 -0
- {akshare_proxy_patch-0.2.13 → akshare_proxy_patch-0.4.0}/setup.cfg +0 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: akshare-proxy-patch
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: 针对 AkShare 和 efinance 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
|
|
5
|
+
Home-page: https://github.com/helloyie/akshare-proxy-patch
|
|
6
|
+
Author: cheapproxy.net
|
|
7
|
+
Author-email: cheapproxy <emezxyj1@gmail.com>
|
|
8
|
+
Project-URL: Homepage, https://github.com/helloyie/akshare-proxy-patch
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.6
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: curl_cffi
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: home-page
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
|
|
22
|
+
# AkShare Proxy Patch
|
|
23
|
+
|
|
24
|
+
> 针对 [akshare](https://github.com/akfamily/akshare)、[efinance](https://github.com/Micro-sheep/efinance)、[yfinance](https://github.com/ranaroussi/yfinance) 的🐒插件补丁,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等接口报错问题和 Yahoo `YFRateLimitError` 问题。
|
|
25
|
+
|
|
26
|
+
## ✨ 特性
|
|
27
|
+
|
|
28
|
+
- 解决 `akshare` 接口报错问题
|
|
29
|
+
- 解决 `efinance` 接口报错问题
|
|
30
|
+
- 解决 `yfinance` Yahoo接口报错问题
|
|
31
|
+
|
|
32
|
+
## 📦 安装
|
|
33
|
+
|
|
34
|
+
1. 安装并升级官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 包
|
|
35
|
+
|
|
36
|
+
2. 安装 `akshare-proxy-patch` 插件
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
pip install akshare-proxy-patch==0.4.0
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 🚀 使用方法(akshare / efinance / yfinance)
|
|
43
|
+
|
|
44
|
+
1. [点击前往插件官网](https://ak.cheapproxy.net/dashboard/akshare) 获取 `TOKEN`。
|
|
45
|
+
|
|
46
|
+
2. `akshare` 或 `efinance` 用户:在 **Python 文件顶部**添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
# python 文件顶部添加如下代码
|
|
50
|
+
import akshare_proxy_patch
|
|
51
|
+
|
|
52
|
+
akshare_proxy_patch.install_patch(
|
|
53
|
+
"101.201.173.125",
|
|
54
|
+
auth_token="你的TOKEN",
|
|
55
|
+
retry=30,
|
|
56
|
+
# 封控的域名列表,可自行调整
|
|
57
|
+
hook_domains=[
|
|
58
|
+
"fund.eastmoney.com",
|
|
59
|
+
"push2.eastmoney.com",
|
|
60
|
+
"push2his.eastmoney.com",
|
|
61
|
+
"emweb.securities.eastmoney.com",
|
|
62
|
+
],
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# --------------------------
|
|
66
|
+
# 后续你的正常业务代码保持不变
|
|
67
|
+
# --------------------------
|
|
68
|
+
|
|
69
|
+
# 假如你使用 akshare
|
|
70
|
+
import akshare as ak
|
|
71
|
+
df = ak.stock_zh_a_spot_em()
|
|
72
|
+
|
|
73
|
+
# 假如你使用 efinance
|
|
74
|
+
import efinance as ef
|
|
75
|
+
ef.stock.get_realtime_quotes()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
3. `yfinance` 用户:在 Python 文件顶部添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
# python 文件顶部添加如下代码
|
|
82
|
+
import akshare_proxy_patch
|
|
83
|
+
|
|
84
|
+
akshare_proxy_patch.install_yfinance_patch(
|
|
85
|
+
"101.201.173.125",
|
|
86
|
+
auth_token="你的TOKEN",
|
|
87
|
+
retry=30,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# --------------------------
|
|
91
|
+
# 后续你的正常业务代码保持不变
|
|
92
|
+
# --------------------------
|
|
93
|
+
|
|
94
|
+
import yfinance as yf
|
|
95
|
+
|
|
96
|
+
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 📖 install_patch 参数说明
|
|
100
|
+
|
|
101
|
+
- 参数1:网关
|
|
102
|
+
- 默认为 `101.201.173.125` 不可修改
|
|
103
|
+
- 参数2:TOKEN
|
|
104
|
+
- 授权凭证
|
|
105
|
+
- 参数3:重试次数
|
|
106
|
+
- 默认为30,建议保持不变
|
|
107
|
+
- 参数4:封控的域名列表
|
|
108
|
+
- 接口 `URL` 包含数组中的其中一条,就会走插件。
|
|
109
|
+
- 可点击 `ak` 或 `ef` 函数查看接口源码对应的 `URL`,根据封控情况细化可以降低积分消耗。
|
|
110
|
+
- 如只封控 `stock_zh_a_spot_em` 这个接口,`hook_domains` 可设置为 `["https://82.push2.eastmoney.com/api/qt/clist/get"]`。
|
|
111
|
+
|
|
112
|
+
## 🛠️ 如何在 aktools 内集成插件?
|
|
113
|
+
|
|
114
|
+
`aktools` 想要集成插件,需要新建一个 `akt.py` 替换官方的 `python -m aktools` 启动命令,下面是 `akt.py` 内容:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
# 添加插件
|
|
118
|
+
import akshare_proxy_patch
|
|
119
|
+
|
|
120
|
+
akshare_proxy_patch.install_patch(
|
|
121
|
+
"101.201.173.125",
|
|
122
|
+
auth_token="你的TOKEN",
|
|
123
|
+
retry=30,
|
|
124
|
+
# 封控的域名列表,可自行调整
|
|
125
|
+
hook_domains=[
|
|
126
|
+
"fund.eastmoney.com",
|
|
127
|
+
"push2.eastmoney.com",
|
|
128
|
+
"push2his.eastmoney.com",
|
|
129
|
+
"emweb.securities.eastmoney.com",
|
|
130
|
+
],
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# 启动 aktools
|
|
134
|
+
import uvicorn
|
|
135
|
+
|
|
136
|
+
if __name__ == '__main__':
|
|
137
|
+
uvicorn.run(
|
|
138
|
+
"aktools.main:app",
|
|
139
|
+
host="0.0.0.0",
|
|
140
|
+
port=8080,
|
|
141
|
+
reload=False,
|
|
142
|
+
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
143
|
+
workers=4,
|
|
144
|
+
log_level="info"
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
149
|
+
|
|
150
|
+
## ❓ 我没使用 akshare 或 efinance,能集成插件吗?
|
|
151
|
+
|
|
152
|
+
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
153
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=&version=0.2.13) 自行实现封控解除。
|
|
154
|
+
|
|
155
|
+
## 💬 使用问题交流群
|
|
156
|
+
|
|
157
|
+
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
158
|
+
|
|
159
|
+

|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# AkShare Proxy Patch
|
|
2
|
+
|
|
3
|
+
> 针对 [akshare](https://github.com/akfamily/akshare)、[efinance](https://github.com/Micro-sheep/efinance)、[yfinance](https://github.com/ranaroussi/yfinance) 的🐒插件补丁,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等接口报错问题和 Yahoo `YFRateLimitError` 问题。
|
|
4
|
+
|
|
5
|
+
## ✨ 特性
|
|
6
|
+
|
|
7
|
+
- 解决 `akshare` 接口报错问题
|
|
8
|
+
- 解决 `efinance` 接口报错问题
|
|
9
|
+
- 解决 `yfinance` Yahoo接口报错问题
|
|
10
|
+
|
|
11
|
+
## 📦 安装
|
|
12
|
+
|
|
13
|
+
1. 安装并升级官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 包
|
|
14
|
+
|
|
15
|
+
2. 安装 `akshare-proxy-patch` 插件
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
pip install akshare-proxy-patch==0.4.0
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 🚀 使用方法(akshare / efinance / yfinance)
|
|
22
|
+
|
|
23
|
+
1. [点击前往插件官网](https://ak.cheapproxy.net/dashboard/akshare) 获取 `TOKEN`。
|
|
24
|
+
|
|
25
|
+
2. `akshare` 或 `efinance` 用户:在 **Python 文件顶部**添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
# python 文件顶部添加如下代码
|
|
29
|
+
import akshare_proxy_patch
|
|
30
|
+
|
|
31
|
+
akshare_proxy_patch.install_patch(
|
|
32
|
+
"101.201.173.125",
|
|
33
|
+
auth_token="你的TOKEN",
|
|
34
|
+
retry=30,
|
|
35
|
+
# 封控的域名列表,可自行调整
|
|
36
|
+
hook_domains=[
|
|
37
|
+
"fund.eastmoney.com",
|
|
38
|
+
"push2.eastmoney.com",
|
|
39
|
+
"push2his.eastmoney.com",
|
|
40
|
+
"emweb.securities.eastmoney.com",
|
|
41
|
+
],
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# --------------------------
|
|
45
|
+
# 后续你的正常业务代码保持不变
|
|
46
|
+
# --------------------------
|
|
47
|
+
|
|
48
|
+
# 假如你使用 akshare
|
|
49
|
+
import akshare as ak
|
|
50
|
+
df = ak.stock_zh_a_spot_em()
|
|
51
|
+
|
|
52
|
+
# 假如你使用 efinance
|
|
53
|
+
import efinance as ef
|
|
54
|
+
ef.stock.get_realtime_quotes()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
3. `yfinance` 用户:在 Python 文件顶部添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
# python 文件顶部添加如下代码
|
|
61
|
+
import akshare_proxy_patch
|
|
62
|
+
|
|
63
|
+
akshare_proxy_patch.install_yfinance_patch(
|
|
64
|
+
"101.201.173.125",
|
|
65
|
+
auth_token="你的TOKEN",
|
|
66
|
+
retry=30,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# --------------------------
|
|
70
|
+
# 后续你的正常业务代码保持不变
|
|
71
|
+
# --------------------------
|
|
72
|
+
|
|
73
|
+
import yfinance as yf
|
|
74
|
+
|
|
75
|
+
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## 📖 install_patch 参数说明
|
|
79
|
+
|
|
80
|
+
- 参数1:网关
|
|
81
|
+
- 默认为 `101.201.173.125` 不可修改
|
|
82
|
+
- 参数2:TOKEN
|
|
83
|
+
- 授权凭证
|
|
84
|
+
- 参数3:重试次数
|
|
85
|
+
- 默认为30,建议保持不变
|
|
86
|
+
- 参数4:封控的域名列表
|
|
87
|
+
- 接口 `URL` 包含数组中的其中一条,就会走插件。
|
|
88
|
+
- 可点击 `ak` 或 `ef` 函数查看接口源码对应的 `URL`,根据封控情况细化可以降低积分消耗。
|
|
89
|
+
- 如只封控 `stock_zh_a_spot_em` 这个接口,`hook_domains` 可设置为 `["https://82.push2.eastmoney.com/api/qt/clist/get"]`。
|
|
90
|
+
|
|
91
|
+
## 🛠️ 如何在 aktools 内集成插件?
|
|
92
|
+
|
|
93
|
+
`aktools` 想要集成插件,需要新建一个 `akt.py` 替换官方的 `python -m aktools` 启动命令,下面是 `akt.py` 内容:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
# 添加插件
|
|
97
|
+
import akshare_proxy_patch
|
|
98
|
+
|
|
99
|
+
akshare_proxy_patch.install_patch(
|
|
100
|
+
"101.201.173.125",
|
|
101
|
+
auth_token="你的TOKEN",
|
|
102
|
+
retry=30,
|
|
103
|
+
# 封控的域名列表,可自行调整
|
|
104
|
+
hook_domains=[
|
|
105
|
+
"fund.eastmoney.com",
|
|
106
|
+
"push2.eastmoney.com",
|
|
107
|
+
"push2his.eastmoney.com",
|
|
108
|
+
"emweb.securities.eastmoney.com",
|
|
109
|
+
],
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# 启动 aktools
|
|
113
|
+
import uvicorn
|
|
114
|
+
|
|
115
|
+
if __name__ == '__main__':
|
|
116
|
+
uvicorn.run(
|
|
117
|
+
"aktools.main:app",
|
|
118
|
+
host="0.0.0.0",
|
|
119
|
+
port=8080,
|
|
120
|
+
reload=False,
|
|
121
|
+
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
122
|
+
workers=4,
|
|
123
|
+
log_level="info"
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
128
|
+
|
|
129
|
+
## ❓ 我没使用 akshare 或 efinance,能集成插件吗?
|
|
130
|
+
|
|
131
|
+
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
132
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=&version=0.2.13) 自行实现封控解除。
|
|
133
|
+
|
|
134
|
+
## 💬 使用问题交流群
|
|
135
|
+
|
|
136
|
+
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
137
|
+
|
|
138
|
+

|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import random
|
|
3
|
+
import threading
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
# 1. 导入必要的库
|
|
7
|
+
try:
|
|
8
|
+
from curl_cffi import requests as curl_requests
|
|
9
|
+
from curl_cffi.requests import BrowserType
|
|
10
|
+
from curl_cffi.requests.errors import RequestsError as RequestException
|
|
11
|
+
except ImportError:
|
|
12
|
+
raise ImportError("请执行 pip install curl_cffi 来安装依赖")
|
|
13
|
+
|
|
14
|
+
import requests as std_requests
|
|
15
|
+
|
|
16
|
+
__version__ = "0.4.0"
|
|
17
|
+
|
|
18
|
+
# 授权接口固定使用标准 requests,避免干扰
|
|
19
|
+
_auth_session = std_requests.Session()
|
|
20
|
+
|
|
21
|
+
target_browsers = [
|
|
22
|
+
b
|
|
23
|
+
for b in BrowserType.__dict__.values()
|
|
24
|
+
if isinstance(b, str) and (b.startswith("chrome") or b.startswith("edge"))
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class AuthCache:
|
|
29
|
+
def __init__(self):
|
|
30
|
+
self.data = None
|
|
31
|
+
self.expire_at = 0
|
|
32
|
+
self.lock = threading.Lock()
|
|
33
|
+
self.ttl = 28
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
_cache = AuthCache()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_auth_config_with_cache(auth_url, auth_token):
|
|
40
|
+
now = time.time()
|
|
41
|
+
if _cache.data and now < _cache.expire_at:
|
|
42
|
+
return _cache.data
|
|
43
|
+
with _cache.lock:
|
|
44
|
+
if _cache.data and now < _cache.expire_at:
|
|
45
|
+
return _cache.data
|
|
46
|
+
try:
|
|
47
|
+
resp = _auth_session.get(
|
|
48
|
+
auth_url,
|
|
49
|
+
params={"token": auth_token, "version": __version__},
|
|
50
|
+
timeout=(1.5, 3),
|
|
51
|
+
)
|
|
52
|
+
data = resp.json()
|
|
53
|
+
if data.get("ua"):
|
|
54
|
+
_cache.data = data
|
|
55
|
+
_cache.expire_at = now + _cache.ttl
|
|
56
|
+
return data
|
|
57
|
+
print(f"授权失败: {data.get('error_msg')}")
|
|
58
|
+
except:
|
|
59
|
+
pass
|
|
60
|
+
return _cache.data
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
default_hook_domains = [
|
|
64
|
+
"fund.eastmoney.com",
|
|
65
|
+
"push2.eastmoney.com",
|
|
66
|
+
"push2his.eastmoney.com",
|
|
67
|
+
"emweb.securities.eastmoney.com",
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def install_patch(
|
|
72
|
+
auth_ip, auth_token="", retry=30, hook_domains=default_hook_domains, timeout=5
|
|
73
|
+
):
|
|
74
|
+
# 获取原始的 curl_cffi Session 类
|
|
75
|
+
# 1. 解决 Linux 下的 AttributeError: 'curl_cffi.requests' has no attribute 'adapters'
|
|
76
|
+
# 动态将标准 requests 的子模块挂载到 curl_requests 上
|
|
77
|
+
needed_submodules = [
|
|
78
|
+
"adapters",
|
|
79
|
+
"auth",
|
|
80
|
+
"cookies",
|
|
81
|
+
"exceptions",
|
|
82
|
+
"models",
|
|
83
|
+
"status_codes",
|
|
84
|
+
"structures",
|
|
85
|
+
"utils",
|
|
86
|
+
"packages",
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
setattr(curl_requests, "RequestException", RequestException)
|
|
90
|
+
for sub in needed_submodules:
|
|
91
|
+
if not hasattr(curl_requests, sub):
|
|
92
|
+
# 优先从标准 requests 借用这些定义,保证 akshare 里的 isinstance 或常量检查能过
|
|
93
|
+
setattr(curl_requests, sub, getattr(std_requests, sub, None))
|
|
94
|
+
|
|
95
|
+
_BaseSession = curl_requests.Session
|
|
96
|
+
|
|
97
|
+
# 定义兼容 Windows 调用的子类
|
|
98
|
+
class PatchedSession(_BaseSession):
|
|
99
|
+
def mount(self, prefix, adapter):
|
|
100
|
+
pass
|
|
101
|
+
|
|
102
|
+
def request(self, method, url, **kwargs):
|
|
103
|
+
is_target = any(d in (url or "") for d in hook_domains)
|
|
104
|
+
clean_url = (url or "").split("?")[0].lower()
|
|
105
|
+
if (
|
|
106
|
+
not is_target
|
|
107
|
+
or clean_url.endswith(".js")
|
|
108
|
+
or clean_url.endswith(".html")
|
|
109
|
+
):
|
|
110
|
+
return super().request(method, url, **kwargs)
|
|
111
|
+
|
|
112
|
+
auth_url = f"http://{auth_ip}:47001/api/akshare-auth"
|
|
113
|
+
|
|
114
|
+
for i in range(retry):
|
|
115
|
+
auth_res = get_auth_config_with_cache(auth_url, auth_token)
|
|
116
|
+
if not auth_res:
|
|
117
|
+
time.sleep(0.05)
|
|
118
|
+
continue
|
|
119
|
+
|
|
120
|
+
# 适配参数
|
|
121
|
+
headers = kwargs.get("headers") or {}
|
|
122
|
+
headers["User-Agent"] = auth_res["ua"]
|
|
123
|
+
kwargs["headers"] = headers
|
|
124
|
+
kwargs["proxies"] = {
|
|
125
|
+
"http": auth_res["proxy"],
|
|
126
|
+
"https": auth_res["proxy"],
|
|
127
|
+
}
|
|
128
|
+
kwargs["timeout"] = timeout
|
|
129
|
+
|
|
130
|
+
kwargs["impersonate"] = random.choice(target_browsers)
|
|
131
|
+
# print(auth_res["proxy"], i, "=============")
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
# 关键:调用 curl_cffi 的原生 C 实现
|
|
135
|
+
resp = super().request(method, url, **kwargs)
|
|
136
|
+
if resp.status_code == 200:
|
|
137
|
+
# 业务逻辑验证...
|
|
138
|
+
return resp
|
|
139
|
+
with _cache.lock:
|
|
140
|
+
_cache.expire_at = 0
|
|
141
|
+
except:
|
|
142
|
+
with _cache.lock:
|
|
143
|
+
_cache.expire_at = 0
|
|
144
|
+
time.sleep(0.05)
|
|
145
|
+
|
|
146
|
+
return super().request(method, url, **kwargs)
|
|
147
|
+
|
|
148
|
+
# --- 核心改造:针对 Windows 的原地注入 ---
|
|
149
|
+
|
|
150
|
+
# 定义顶层包装函数
|
|
151
|
+
def patched_get(url, params=None, **kwargs):
|
|
152
|
+
with PatchedSession() as s:
|
|
153
|
+
return s.get(url, params=params, **kwargs)
|
|
154
|
+
|
|
155
|
+
def patched_post(url, data=None, json=None, **kwargs):
|
|
156
|
+
with PatchedSession() as s:
|
|
157
|
+
return s.post(url, data=data, json=json, **kwargs)
|
|
158
|
+
|
|
159
|
+
# 1. 替换 curl_requests 的成员
|
|
160
|
+
curl_requests.Session = PatchedSession
|
|
161
|
+
curl_requests.get = patched_get
|
|
162
|
+
curl_requests.post = patched_post
|
|
163
|
+
|
|
164
|
+
# 2. 【核心】原地修改 sys.modules 中的 requests 对象
|
|
165
|
+
# 即使 akshare 已经加载了 requests,我们直接修改 requests 模块的内容
|
|
166
|
+
if "requests" in sys.modules:
|
|
167
|
+
req_mod = sys.modules["requests"]
|
|
168
|
+
req_mod.Session = PatchedSession
|
|
169
|
+
req_mod.get = patched_get
|
|
170
|
+
req_mod.post = patched_post
|
|
171
|
+
req_mod.request = patched_get # 部分库直接调 request
|
|
172
|
+
|
|
173
|
+
# 3. 确保后续导入重定向
|
|
174
|
+
sys.modules["requests"] = curl_requests
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def install_yfinance_patch(
|
|
178
|
+
auth_ip, auth_token="", retry=30, hook_domains=["finance.yahoo.com"]
|
|
179
|
+
):
|
|
180
|
+
from .yfinance import install_yfinance_patch_main
|
|
181
|
+
|
|
182
|
+
install_yfinance_patch_main(auth_ip, auth_token, retry, hook_domains)
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import time
|
|
2
2
|
import threading
|
|
3
|
-
import requests
|
|
4
|
-
from urllib.parse import urlparse
|
|
3
|
+
from curl_cffi import requests
|
|
5
4
|
|
|
6
|
-
__version__ = "0.
|
|
7
|
-
# 备份 Session 的原始 request 方法,这是所有 requests.get/post 的最终入口
|
|
5
|
+
__version__ = "0.3.0"
|
|
8
6
|
_original_request = requests.Session.request
|
|
9
7
|
_auth_session = requests.Session()
|
|
10
8
|
|
|
@@ -14,7 +12,7 @@ class AuthCache:
|
|
|
14
12
|
self.data = None
|
|
15
13
|
self.expire_at = 0
|
|
16
14
|
self.lock = threading.Lock()
|
|
17
|
-
self.ttl =
|
|
15
|
+
self.ttl = 30
|
|
18
16
|
|
|
19
17
|
|
|
20
18
|
_cache = AuthCache()
|
|
@@ -38,7 +36,7 @@ def get_auth_config_with_cache(auth_url, auth_token):
|
|
|
38
36
|
timeout=(1.5, 3),
|
|
39
37
|
)
|
|
40
38
|
data = resp.json()
|
|
41
|
-
if data.get("
|
|
39
|
+
if data.get("proxy"):
|
|
42
40
|
_cache.data = data
|
|
43
41
|
_cache.expire_at = now + _cache.ttl
|
|
44
42
|
return data
|
|
@@ -49,26 +47,15 @@ def get_auth_config_with_cache(auth_url, auth_token):
|
|
|
49
47
|
return _cache.data
|
|
50
48
|
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
default_hook_domains = [
|
|
54
|
-
"fund.eastmoney.com",
|
|
55
|
-
"push2.eastmoney.com",
|
|
56
|
-
"push2his.eastmoney.com",
|
|
57
|
-
"emweb.securities.eastmoney.com",
|
|
58
|
-
]
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def install_patch(auth_ip, auth_token="", retry=30, hook_domains=default_hook_domains):
|
|
50
|
+
def install_yfinance_patch_main(auth_ip, auth_token="", retry=30, hook_domains=[]):
|
|
62
51
|
def patched_request(self, method, url, **kwargs):
|
|
63
52
|
# 排除非目标域名
|
|
64
53
|
is_target = any(d in (url or "") for d in hook_domains)
|
|
65
|
-
is_js = urlparse(url or "").path.lower().endswith(".js")
|
|
66
|
-
is_html = urlparse(url or "").path.lower().endswith(".html")
|
|
67
54
|
|
|
68
|
-
if not is_target
|
|
55
|
+
if not is_target:
|
|
69
56
|
return _original_request(self, method, url, **kwargs)
|
|
70
57
|
|
|
71
|
-
auth_url = f"http://{auth_ip}:47001/api/
|
|
58
|
+
auth_url = f"http://{auth_ip}:47001/api/yfinance-auth"
|
|
72
59
|
|
|
73
60
|
# 重试逻辑
|
|
74
61
|
for _ in range(retry):
|
|
@@ -77,13 +64,6 @@ def install_patch(auth_ip, auth_token="", retry=30, hook_domains=default_hook_do
|
|
|
77
64
|
time.sleep(0.05)
|
|
78
65
|
continue
|
|
79
66
|
|
|
80
|
-
# 处理 Headers:确保不破坏业务代码传入的 headers
|
|
81
|
-
headers = kwargs.get("headers") or {}
|
|
82
|
-
headers["User-Agent"] = auth_res["ua"]
|
|
83
|
-
headers["Cookie"] = (
|
|
84
|
-
f"nid18={auth_res['nid18']}; nid18_create_time={auth_res['nid18_create_time']}"
|
|
85
|
-
)
|
|
86
|
-
kwargs["headers"] = headers
|
|
87
67
|
kwargs["proxies"] = {
|
|
88
68
|
"http": auth_res["proxy"],
|
|
89
69
|
"https": auth_res["proxy"],
|
|
@@ -110,14 +90,17 @@ def install_patch(auth_ip, auth_token="", retry=30, hook_domains=default_hook_do
|
|
|
110
90
|
with _cache.lock:
|
|
111
91
|
_cache.expire_at = 0
|
|
112
92
|
time.sleep(0.05)
|
|
113
|
-
|
|
114
|
-
# 最终尝试
|
|
115
93
|
return _original_request(self, method, url, **kwargs)
|
|
116
94
|
|
|
117
|
-
# 关键:全局替换 Session 的 request 入口
|
|
118
95
|
requests.Session.request = patched_request
|
|
119
96
|
|
|
120
97
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
98
|
+
def uninstall_yfinance_patch_main():
|
|
99
|
+
"""
|
|
100
|
+
恢复 requests.Session.request 到原始状态
|
|
101
|
+
"""
|
|
102
|
+
if hasattr(requests.Session, "request"):
|
|
103
|
+
requests.Session.request = _original_request
|
|
104
|
+
print("yfinance_patch 已成功卸载")
|
|
105
|
+
else:
|
|
106
|
+
print("未发现 yfinance_patch 或已处于原始状态。")
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: akshare-proxy-patch
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: 针对 AkShare 和 efinance 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
|
|
5
|
+
Home-page: https://github.com/helloyie/akshare-proxy-patch
|
|
6
|
+
Author: cheapproxy.net
|
|
7
|
+
Author-email: cheapproxy <emezxyj1@gmail.com>
|
|
8
|
+
Project-URL: Homepage, https://github.com/helloyie/akshare-proxy-patch
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.6
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: curl_cffi
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: home-page
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
|
|
22
|
+
# AkShare Proxy Patch
|
|
23
|
+
|
|
24
|
+
> 针对 [akshare](https://github.com/akfamily/akshare)、[efinance](https://github.com/Micro-sheep/efinance)、[yfinance](https://github.com/ranaroussi/yfinance) 的🐒插件补丁,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等接口报错问题和 Yahoo `YFRateLimitError` 问题。
|
|
25
|
+
|
|
26
|
+
## ✨ 特性
|
|
27
|
+
|
|
28
|
+
- 解决 `akshare` 接口报错问题
|
|
29
|
+
- 解决 `efinance` 接口报错问题
|
|
30
|
+
- 解决 `yfinance` Yahoo接口报错问题
|
|
31
|
+
|
|
32
|
+
## 📦 安装
|
|
33
|
+
|
|
34
|
+
1. 安装并升级官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 包
|
|
35
|
+
|
|
36
|
+
2. 安装 `akshare-proxy-patch` 插件
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
pip install akshare-proxy-patch==0.4.0
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 🚀 使用方法(akshare / efinance / yfinance)
|
|
43
|
+
|
|
44
|
+
1. [点击前往插件官网](https://ak.cheapproxy.net/dashboard/akshare) 获取 `TOKEN`。
|
|
45
|
+
|
|
46
|
+
2. `akshare` 或 `efinance` 用户:在 **Python 文件顶部**添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
# python 文件顶部添加如下代码
|
|
50
|
+
import akshare_proxy_patch
|
|
51
|
+
|
|
52
|
+
akshare_proxy_patch.install_patch(
|
|
53
|
+
"101.201.173.125",
|
|
54
|
+
auth_token="你的TOKEN",
|
|
55
|
+
retry=30,
|
|
56
|
+
# 封控的域名列表,可自行调整
|
|
57
|
+
hook_domains=[
|
|
58
|
+
"fund.eastmoney.com",
|
|
59
|
+
"push2.eastmoney.com",
|
|
60
|
+
"push2his.eastmoney.com",
|
|
61
|
+
"emweb.securities.eastmoney.com",
|
|
62
|
+
],
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# --------------------------
|
|
66
|
+
# 后续你的正常业务代码保持不变
|
|
67
|
+
# --------------------------
|
|
68
|
+
|
|
69
|
+
# 假如你使用 akshare
|
|
70
|
+
import akshare as ak
|
|
71
|
+
df = ak.stock_zh_a_spot_em()
|
|
72
|
+
|
|
73
|
+
# 假如你使用 efinance
|
|
74
|
+
import efinance as ef
|
|
75
|
+
ef.stock.get_realtime_quotes()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
3. `yfinance` 用户:在 Python 文件顶部添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
# python 文件顶部添加如下代码
|
|
82
|
+
import akshare_proxy_patch
|
|
83
|
+
|
|
84
|
+
akshare_proxy_patch.install_yfinance_patch(
|
|
85
|
+
"101.201.173.125",
|
|
86
|
+
auth_token="你的TOKEN",
|
|
87
|
+
retry=30,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# --------------------------
|
|
91
|
+
# 后续你的正常业务代码保持不变
|
|
92
|
+
# --------------------------
|
|
93
|
+
|
|
94
|
+
import yfinance as yf
|
|
95
|
+
|
|
96
|
+
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 📖 install_patch 参数说明
|
|
100
|
+
|
|
101
|
+
- 参数1:网关
|
|
102
|
+
- 默认为 `101.201.173.125` 不可修改
|
|
103
|
+
- 参数2:TOKEN
|
|
104
|
+
- 授权凭证
|
|
105
|
+
- 参数3:重试次数
|
|
106
|
+
- 默认为30,建议保持不变
|
|
107
|
+
- 参数4:封控的域名列表
|
|
108
|
+
- 接口 `URL` 包含数组中的其中一条,就会走插件。
|
|
109
|
+
- 可点击 `ak` 或 `ef` 函数查看接口源码对应的 `URL`,根据封控情况细化可以降低积分消耗。
|
|
110
|
+
- 如只封控 `stock_zh_a_spot_em` 这个接口,`hook_domains` 可设置为 `["https://82.push2.eastmoney.com/api/qt/clist/get"]`。
|
|
111
|
+
|
|
112
|
+
## 🛠️ 如何在 aktools 内集成插件?
|
|
113
|
+
|
|
114
|
+
`aktools` 想要集成插件,需要新建一个 `akt.py` 替换官方的 `python -m aktools` 启动命令,下面是 `akt.py` 内容:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
# 添加插件
|
|
118
|
+
import akshare_proxy_patch
|
|
119
|
+
|
|
120
|
+
akshare_proxy_patch.install_patch(
|
|
121
|
+
"101.201.173.125",
|
|
122
|
+
auth_token="你的TOKEN",
|
|
123
|
+
retry=30,
|
|
124
|
+
# 封控的域名列表,可自行调整
|
|
125
|
+
hook_domains=[
|
|
126
|
+
"fund.eastmoney.com",
|
|
127
|
+
"push2.eastmoney.com",
|
|
128
|
+
"push2his.eastmoney.com",
|
|
129
|
+
"emweb.securities.eastmoney.com",
|
|
130
|
+
],
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# 启动 aktools
|
|
134
|
+
import uvicorn
|
|
135
|
+
|
|
136
|
+
if __name__ == '__main__':
|
|
137
|
+
uvicorn.run(
|
|
138
|
+
"aktools.main:app",
|
|
139
|
+
host="0.0.0.0",
|
|
140
|
+
port=8080,
|
|
141
|
+
reload=False,
|
|
142
|
+
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
143
|
+
workers=4,
|
|
144
|
+
log_level="info"
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
149
|
+
|
|
150
|
+
## ❓ 我没使用 akshare 或 efinance,能集成插件吗?
|
|
151
|
+
|
|
152
|
+
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
153
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=&version=0.2.13) 自行实现封控解除。
|
|
154
|
+
|
|
155
|
+
## 💬 使用问题交流群
|
|
156
|
+
|
|
157
|
+
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
158
|
+
|
|
159
|
+

|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "akshare-proxy-patch" # 包名,需在 PyPI 唯一
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="cheapproxy", email="emezxyj1@gmail.com" },
|
|
10
10
|
]
|
|
@@ -13,6 +13,7 @@ readme = "README.md"
|
|
|
13
13
|
requires-python = ">=3.7"
|
|
14
14
|
dependencies = [
|
|
15
15
|
"requests",
|
|
16
|
+
"curl_cffi",
|
|
16
17
|
]
|
|
17
18
|
classifiers = [
|
|
18
19
|
"Programming Language :: Python :: 3",
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name="akshare-proxy-patch", # 包名,用户 pip install 时的名称
|
|
8
|
-
version="0.
|
|
8
|
+
version="0.4.0",
|
|
9
9
|
author="cheapproxy.net",
|
|
10
10
|
author_email="emezxyj1@gmail.com",
|
|
11
11
|
description="AkShare 和 efinance 报错全局Hook",
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: akshare-proxy-patch
|
|
3
|
-
Version: 0.2.13
|
|
4
|
-
Summary: 针对 AkShare 和 efinance 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
|
|
5
|
-
Home-page: https://github.com/helloyie/akshare-proxy-patch
|
|
6
|
-
Author: cheapproxy.net
|
|
7
|
-
Author-email: cheapproxy <emezxyj1@gmail.com>
|
|
8
|
-
Project-URL: Homepage, https://github.com/helloyie/akshare-proxy-patch
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Operating System :: OS Independent
|
|
12
|
-
Requires-Python: >=3.6
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
License-File: LICENSE
|
|
15
|
-
Requires-Dist: requests
|
|
16
|
-
Dynamic: author
|
|
17
|
-
Dynamic: home-page
|
|
18
|
-
Dynamic: license-file
|
|
19
|
-
Dynamic: requires-python
|
|
20
|
-
|
|
21
|
-
# AkShare Proxy Patch
|
|
22
|
-
|
|
23
|
-
针对 `akshare` 和 `efinance` 的插件补丁,自动为接口注入请求头,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等东财接口报错问题。
|
|
24
|
-
|
|
25
|
-
## 安装
|
|
26
|
-
|
|
27
|
-
1. 安装好官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 包
|
|
28
|
-
|
|
29
|
-
2. 安装 `akshare-proxy-patch` 插件
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
pip install akshare-proxy-patch==0.2.13
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## 使用方法
|
|
36
|
-
|
|
37
|
-
`akshare` 和 `efinance` 使用方式一致,在文件顶部添加2行代码即可,无需其他额外操作。
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
# python 文件顶部添加如下代码
|
|
41
|
-
import akshare_proxy_patch
|
|
42
|
-
|
|
43
|
-
akshare_proxy_patch.install_patch(
|
|
44
|
-
"101.201.173.125",
|
|
45
|
-
auth_token="",
|
|
46
|
-
retry=30,
|
|
47
|
-
hook_domains=[
|
|
48
|
-
"fund.eastmoney.com",
|
|
49
|
-
"push2.eastmoney.com",
|
|
50
|
-
"push2his.eastmoney.com",
|
|
51
|
-
"emweb.securities.eastmoney.com",
|
|
52
|
-
],
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
# 后续你的正常业务代码保持不变
|
|
57
|
-
|
|
58
|
-
# 假如你使用 akshare
|
|
59
|
-
import akshare as ak
|
|
60
|
-
df = ak.stock_zh_a_spot_em()
|
|
61
|
-
|
|
62
|
-
# 假如你使用 efinance
|
|
63
|
-
import efinance as ef
|
|
64
|
-
ef.stock.get_realtime_quotes()
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## install_patch 参数说明
|
|
68
|
-
|
|
69
|
-
- 参数1:网关
|
|
70
|
-
- 默认为 `101.201.173.125` 不可修改
|
|
71
|
-
- 参数2:TOKEN
|
|
72
|
-
- 默认为空,每天可免费使用一定次数。如有更多需求,可[点击此处注册](https://ak.cheapproxy.net/dashboard/akshare)申请正式的 `TOKEN`。
|
|
73
|
-
- 参数3:重试次数
|
|
74
|
-
- 默认为30,建议保持不变
|
|
75
|
-
- 参数4:需要hook的域名列表
|
|
76
|
-
- 接口URL包含列表内任意一条域名都会走代理,可以根据封控情况调整或细化以降低积分消耗
|
|
77
|
-
- 如只封控 `stock_zh_a_spot_em` 这个接口,hook_domains=["https://82.push2.eastmoney.com/api/qt/clist/get"] 即可(点击函数查看接口源码找到对应域名)
|
|
78
|
-
|
|
79
|
-
## 如何在 aktools 内集成插件?
|
|
80
|
-
|
|
81
|
-
需要新建一个 `akt.py` 替换官方的启动方式:
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
# 添加插件
|
|
85
|
-
import akshare_proxy_patch
|
|
86
|
-
|
|
87
|
-
akshare_proxy_patch.install_patch(
|
|
88
|
-
"101.201.173.125",
|
|
89
|
-
auth_token="",
|
|
90
|
-
retry=30,
|
|
91
|
-
hook_domains=[
|
|
92
|
-
"fund.eastmoney.com",
|
|
93
|
-
"push2.eastmoney.com",
|
|
94
|
-
"push2his.eastmoney.com",
|
|
95
|
-
"emweb.securities.eastmoney.com",
|
|
96
|
-
],
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
# 启动 aktools
|
|
100
|
-
import uvicorn
|
|
101
|
-
|
|
102
|
-
if __name__ == '__main__':
|
|
103
|
-
uvicorn.run(
|
|
104
|
-
"aktools.main:app",
|
|
105
|
-
host="0.0.0.0",
|
|
106
|
-
port=8080,
|
|
107
|
-
reload=False,
|
|
108
|
-
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
109
|
-
workers=4,
|
|
110
|
-
log_level="info"
|
|
111
|
-
)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
然后执行 `python akt.py` 即可启动并正常使用 `aktools`。
|
|
115
|
-
|
|
116
|
-
## 我是手动爬取的接口,能集成插件吗?
|
|
117
|
-
|
|
118
|
-
能。如果您没有使用 `akshare` 或 `efinance`,而是手动调用的接口,只要代码是使用的 `requests`,插件都能 hook 住请求,正常工作。
|
|
119
|
-
|
|
120
|
-
## 使用问题交流群
|
|
121
|
-
|
|
122
|
-
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
123
|
-
|
|
124
|
-

|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
# AkShare Proxy Patch
|
|
2
|
-
|
|
3
|
-
针对 `akshare` 和 `efinance` 的插件补丁,自动为接口注入请求头,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等东财接口报错问题。
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
7
|
-
1. 安装好官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 包
|
|
8
|
-
|
|
9
|
-
2. 安装 `akshare-proxy-patch` 插件
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
pip install akshare-proxy-patch==0.2.13
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## 使用方法
|
|
16
|
-
|
|
17
|
-
`akshare` 和 `efinance` 使用方式一致,在文件顶部添加2行代码即可,无需其他额外操作。
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
# python 文件顶部添加如下代码
|
|
21
|
-
import akshare_proxy_patch
|
|
22
|
-
|
|
23
|
-
akshare_proxy_patch.install_patch(
|
|
24
|
-
"101.201.173.125",
|
|
25
|
-
auth_token="",
|
|
26
|
-
retry=30,
|
|
27
|
-
hook_domains=[
|
|
28
|
-
"fund.eastmoney.com",
|
|
29
|
-
"push2.eastmoney.com",
|
|
30
|
-
"push2his.eastmoney.com",
|
|
31
|
-
"emweb.securities.eastmoney.com",
|
|
32
|
-
],
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# 后续你的正常业务代码保持不变
|
|
37
|
-
|
|
38
|
-
# 假如你使用 akshare
|
|
39
|
-
import akshare as ak
|
|
40
|
-
df = ak.stock_zh_a_spot_em()
|
|
41
|
-
|
|
42
|
-
# 假如你使用 efinance
|
|
43
|
-
import efinance as ef
|
|
44
|
-
ef.stock.get_realtime_quotes()
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## install_patch 参数说明
|
|
48
|
-
|
|
49
|
-
- 参数1:网关
|
|
50
|
-
- 默认为 `101.201.173.125` 不可修改
|
|
51
|
-
- 参数2:TOKEN
|
|
52
|
-
- 默认为空,每天可免费使用一定次数。如有更多需求,可[点击此处注册](https://ak.cheapproxy.net/dashboard/akshare)申请正式的 `TOKEN`。
|
|
53
|
-
- 参数3:重试次数
|
|
54
|
-
- 默认为30,建议保持不变
|
|
55
|
-
- 参数4:需要hook的域名列表
|
|
56
|
-
- 接口URL包含列表内任意一条域名都会走代理,可以根据封控情况调整或细化以降低积分消耗
|
|
57
|
-
- 如只封控 `stock_zh_a_spot_em` 这个接口,hook_domains=["https://82.push2.eastmoney.com/api/qt/clist/get"] 即可(点击函数查看接口源码找到对应域名)
|
|
58
|
-
|
|
59
|
-
## 如何在 aktools 内集成插件?
|
|
60
|
-
|
|
61
|
-
需要新建一个 `akt.py` 替换官方的启动方式:
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
# 添加插件
|
|
65
|
-
import akshare_proxy_patch
|
|
66
|
-
|
|
67
|
-
akshare_proxy_patch.install_patch(
|
|
68
|
-
"101.201.173.125",
|
|
69
|
-
auth_token="",
|
|
70
|
-
retry=30,
|
|
71
|
-
hook_domains=[
|
|
72
|
-
"fund.eastmoney.com",
|
|
73
|
-
"push2.eastmoney.com",
|
|
74
|
-
"push2his.eastmoney.com",
|
|
75
|
-
"emweb.securities.eastmoney.com",
|
|
76
|
-
],
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
# 启动 aktools
|
|
80
|
-
import uvicorn
|
|
81
|
-
|
|
82
|
-
if __name__ == '__main__':
|
|
83
|
-
uvicorn.run(
|
|
84
|
-
"aktools.main:app",
|
|
85
|
-
host="0.0.0.0",
|
|
86
|
-
port=8080,
|
|
87
|
-
reload=False,
|
|
88
|
-
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
89
|
-
workers=4,
|
|
90
|
-
log_level="info"
|
|
91
|
-
)
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
然后执行 `python akt.py` 即可启动并正常使用 `aktools`。
|
|
95
|
-
|
|
96
|
-
## 我是手动爬取的接口,能集成插件吗?
|
|
97
|
-
|
|
98
|
-
能。如果您没有使用 `akshare` 或 `efinance`,而是手动调用的接口,只要代码是使用的 `requests`,插件都能 hook 住请求,正常工作。
|
|
99
|
-
|
|
100
|
-
## 使用问题交流群
|
|
101
|
-
|
|
102
|
-
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
103
|
-
|
|
104
|
-

|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: akshare-proxy-patch
|
|
3
|
-
Version: 0.2.13
|
|
4
|
-
Summary: 针对 AkShare 和 efinance 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
|
|
5
|
-
Home-page: https://github.com/helloyie/akshare-proxy-patch
|
|
6
|
-
Author: cheapproxy.net
|
|
7
|
-
Author-email: cheapproxy <emezxyj1@gmail.com>
|
|
8
|
-
Project-URL: Homepage, https://github.com/helloyie/akshare-proxy-patch
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Operating System :: OS Independent
|
|
12
|
-
Requires-Python: >=3.6
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
License-File: LICENSE
|
|
15
|
-
Requires-Dist: requests
|
|
16
|
-
Dynamic: author
|
|
17
|
-
Dynamic: home-page
|
|
18
|
-
Dynamic: license-file
|
|
19
|
-
Dynamic: requires-python
|
|
20
|
-
|
|
21
|
-
# AkShare Proxy Patch
|
|
22
|
-
|
|
23
|
-
针对 `akshare` 和 `efinance` 的插件补丁,自动为接口注入请求头,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等东财接口报错问题。
|
|
24
|
-
|
|
25
|
-
## 安装
|
|
26
|
-
|
|
27
|
-
1. 安装好官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 包
|
|
28
|
-
|
|
29
|
-
2. 安装 `akshare-proxy-patch` 插件
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
pip install akshare-proxy-patch==0.2.13
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## 使用方法
|
|
36
|
-
|
|
37
|
-
`akshare` 和 `efinance` 使用方式一致,在文件顶部添加2行代码即可,无需其他额外操作。
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
# python 文件顶部添加如下代码
|
|
41
|
-
import akshare_proxy_patch
|
|
42
|
-
|
|
43
|
-
akshare_proxy_patch.install_patch(
|
|
44
|
-
"101.201.173.125",
|
|
45
|
-
auth_token="",
|
|
46
|
-
retry=30,
|
|
47
|
-
hook_domains=[
|
|
48
|
-
"fund.eastmoney.com",
|
|
49
|
-
"push2.eastmoney.com",
|
|
50
|
-
"push2his.eastmoney.com",
|
|
51
|
-
"emweb.securities.eastmoney.com",
|
|
52
|
-
],
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
# 后续你的正常业务代码保持不变
|
|
57
|
-
|
|
58
|
-
# 假如你使用 akshare
|
|
59
|
-
import akshare as ak
|
|
60
|
-
df = ak.stock_zh_a_spot_em()
|
|
61
|
-
|
|
62
|
-
# 假如你使用 efinance
|
|
63
|
-
import efinance as ef
|
|
64
|
-
ef.stock.get_realtime_quotes()
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## install_patch 参数说明
|
|
68
|
-
|
|
69
|
-
- 参数1:网关
|
|
70
|
-
- 默认为 `101.201.173.125` 不可修改
|
|
71
|
-
- 参数2:TOKEN
|
|
72
|
-
- 默认为空,每天可免费使用一定次数。如有更多需求,可[点击此处注册](https://ak.cheapproxy.net/dashboard/akshare)申请正式的 `TOKEN`。
|
|
73
|
-
- 参数3:重试次数
|
|
74
|
-
- 默认为30,建议保持不变
|
|
75
|
-
- 参数4:需要hook的域名列表
|
|
76
|
-
- 接口URL包含列表内任意一条域名都会走代理,可以根据封控情况调整或细化以降低积分消耗
|
|
77
|
-
- 如只封控 `stock_zh_a_spot_em` 这个接口,hook_domains=["https://82.push2.eastmoney.com/api/qt/clist/get"] 即可(点击函数查看接口源码找到对应域名)
|
|
78
|
-
|
|
79
|
-
## 如何在 aktools 内集成插件?
|
|
80
|
-
|
|
81
|
-
需要新建一个 `akt.py` 替换官方的启动方式:
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
# 添加插件
|
|
85
|
-
import akshare_proxy_patch
|
|
86
|
-
|
|
87
|
-
akshare_proxy_patch.install_patch(
|
|
88
|
-
"101.201.173.125",
|
|
89
|
-
auth_token="",
|
|
90
|
-
retry=30,
|
|
91
|
-
hook_domains=[
|
|
92
|
-
"fund.eastmoney.com",
|
|
93
|
-
"push2.eastmoney.com",
|
|
94
|
-
"push2his.eastmoney.com",
|
|
95
|
-
"emweb.securities.eastmoney.com",
|
|
96
|
-
],
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
# 启动 aktools
|
|
100
|
-
import uvicorn
|
|
101
|
-
|
|
102
|
-
if __name__ == '__main__':
|
|
103
|
-
uvicorn.run(
|
|
104
|
-
"aktools.main:app",
|
|
105
|
-
host="0.0.0.0",
|
|
106
|
-
port=8080,
|
|
107
|
-
reload=False,
|
|
108
|
-
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
109
|
-
workers=4,
|
|
110
|
-
log_level="info"
|
|
111
|
-
)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
然后执行 `python akt.py` 即可启动并正常使用 `aktools`。
|
|
115
|
-
|
|
116
|
-
## 我是手动爬取的接口,能集成插件吗?
|
|
117
|
-
|
|
118
|
-
能。如果您没有使用 `akshare` 或 `efinance`,而是手动调用的接口,只要代码是使用的 `requests`,插件都能 hook 住请求,正常工作。
|
|
119
|
-
|
|
120
|
-
## 使用问题交流群
|
|
121
|
-
|
|
122
|
-
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
123
|
-
|
|
124
|
-

|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
requests
|
|
File without changes
|
|
File without changes
|
{akshare_proxy_patch-0.2.13 → akshare_proxy_patch-0.4.0}/akshare_proxy_patch.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|