akshare-proxy-patch 0.2.7__tar.gz → 0.2.9__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.

@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.4
2
+ Name: akshare-proxy-patch
3
+ Version: 0.2.9
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/cheapproxy/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`、`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.8
33
+ ```
34
+
35
+ ## 使用方法
36
+
37
+ `akshare` 和 `efinance` 使用方式一致,在文件顶部添加2行代码即可,无需其他额外操作。
38
+
39
+ ```
40
+ # python 文件顶部添加2行代码
41
+ import akshare_proxy_patch
42
+
43
+ akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
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
+ ## install_patch 参数说明
58
+
59
+ - 参数1:网关
60
+ - 默认为 `101.201.173.125` 不可修改
61
+ - 参数2:TOKEN
62
+ - 默认为空,每天可免费使用一定次数。如有更多需求,可[点击此处注册](https://ak.cheapproxy.net/dashboard/akshare)申请正式的 `TOKEN`。
63
+ - 参数3:重试次数
64
+ - 默认为30,建议保持不变
65
+
66
+ ## 如何在 aktools 内集成插件?
67
+
68
+ 需要新建一个 `akt.py` 替换官方的启动方式:
69
+
70
+ ```
71
+ # 添加插件
72
+ import akshare_proxy_patch
73
+
74
+ akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
75
+
76
+ # 启动 aktools
77
+ import uvicorn
78
+
79
+ if __name__ == '__main__':
80
+ uvicorn.run(
81
+ "aktools.main:app",
82
+ host="0.0.0.0",
83
+ port=8080,
84
+ reload=False,
85
+ # 根据 CPU 核心数调整,推荐 2×核心数 + 1
86
+ workers=4,
87
+ log_level="info"
88
+ )
89
+ ```
90
+
91
+ 然后执行 `python akt.py` 即可启动并正常使用 `aktools`。
92
+
93
+ ## 我是手动爬取的接口,能集成插件吗?
94
+
95
+ 能。如果您没有使用 `akshare` 或 `efinance`,而是手动调用的接口,只要代码是使用的 `requests`,插件都能 hook 住请求,正常工作。
96
+
97
+ ## 使用问题交流群
98
+
99
+ 如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
100
+
101
+ ![7sEblPiT7tEdCPrA3nEyekVYxsMZDDgy.webp](https://picui.ogmua.cn/s1/2026/03/03/69a64a45bbda0.webp)
@@ -0,0 +1,81 @@
1
+ # AkShare Proxy Patch
2
+
3
+ 针对 `akshare` 和 `efinance` 的插件补丁,自动为接口注入请求头,从而避免`stock_zh_a_spot_em`、`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.8
13
+ ```
14
+
15
+ ## 使用方法
16
+
17
+ `akshare` 和 `efinance` 使用方式一致,在文件顶部添加2行代码即可,无需其他额外操作。
18
+
19
+ ```
20
+ # python 文件顶部添加2行代码
21
+ import akshare_proxy_patch
22
+
23
+ akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
24
+
25
+
26
+ # 后续你的正常业务代码保持不变
27
+
28
+ # 假如你使用 akshare
29
+ import akshare as ak
30
+ df = ak.stock_zh_a_spot_em()
31
+
32
+ # 假如你使用 efinance
33
+ import efinance as ef
34
+ ef.stock.get_realtime_quotes()
35
+ ```
36
+
37
+ ## install_patch 参数说明
38
+
39
+ - 参数1:网关
40
+ - 默认为 `101.201.173.125` 不可修改
41
+ - 参数2:TOKEN
42
+ - 默认为空,每天可免费使用一定次数。如有更多需求,可[点击此处注册](https://ak.cheapproxy.net/dashboard/akshare)申请正式的 `TOKEN`。
43
+ - 参数3:重试次数
44
+ - 默认为30,建议保持不变
45
+
46
+ ## 如何在 aktools 内集成插件?
47
+
48
+ 需要新建一个 `akt.py` 替换官方的启动方式:
49
+
50
+ ```
51
+ # 添加插件
52
+ import akshare_proxy_patch
53
+
54
+ akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
55
+
56
+ # 启动 aktools
57
+ import uvicorn
58
+
59
+ if __name__ == '__main__':
60
+ uvicorn.run(
61
+ "aktools.main:app",
62
+ host="0.0.0.0",
63
+ port=8080,
64
+ reload=False,
65
+ # 根据 CPU 核心数调整,推荐 2×核心数 + 1
66
+ workers=4,
67
+ log_level="info"
68
+ )
69
+ ```
70
+
71
+ 然后执行 `python akt.py` 即可启动并正常使用 `aktools`。
72
+
73
+ ## 我是手动爬取的接口,能集成插件吗?
74
+
75
+ 能。如果您没有使用 `akshare` 或 `efinance`,而是手动调用的接口,只要代码是使用的 `requests`,插件都能 hook 住请求,正常工作。
76
+
77
+ ## 使用问题交流群
78
+
79
+ 如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
80
+
81
+ ![7sEblPiT7tEdCPrA3nEyekVYxsMZDDgy.webp](https://picui.ogmua.cn/s1/2026/03/03/69a64a45bbda0.webp)
@@ -1,9 +1,8 @@
1
1
  import time
2
2
  import threading
3
3
  import requests
4
- from requests.adapters import HTTPAdapter
5
4
 
6
- __version__ = "0.2.7"
5
+ __version__ = "0.2.9"
7
6
  # 备份 Session 的原始 request 方法,这是所有 requests.get/post 的最终入口
8
7
  _original_request = requests.Session.request
9
8
  _auth_session = requests.Session()
@@ -14,7 +13,7 @@ class AuthCache:
14
13
  self.data = None
15
14
  self.expire_at = 0
16
15
  self.lock = threading.Lock()
17
- self.ttl = 20
16
+ self.ttl = 28
18
17
 
19
18
 
20
19
  _cache = AuthCache()
@@ -35,7 +34,7 @@ def get_auth_config_with_cache(auth_url, auth_token):
35
34
  resp = _auth_session.get(
36
35
  auth_url,
37
36
  params={"token": auth_token, "version": __version__},
38
- timeout=5,
37
+ timeout=(1.5, 3),
39
38
  )
40
39
  data = resp.json()
41
40
  if data.get("ua"):
@@ -70,7 +69,7 @@ def install_patch(auth_ip, auth_token, retry=30):
70
69
  for _ in range(retry):
71
70
  auth_res = get_auth_config_with_cache(auth_url, auth_token)
72
71
  if not auth_res:
73
- time.sleep(0.5)
72
+ time.sleep(0.05)
74
73
  continue
75
74
 
76
75
  # 处理 Headers:确保不破坏业务代码传入的 headers
@@ -85,21 +84,24 @@ def install_patch(auth_ip, auth_token, retry=30):
85
84
  "https": auth_res["proxy"],
86
85
  }
87
86
 
88
- kwargs["timeout"] = 8
87
+ kwargs["timeout"] = (2.5, 5)
89
88
 
90
89
  try:
91
90
  # 调用原始 request 方法
92
91
  resp = _original_request(self, method, url, **kwargs)
93
92
  if resp.ok:
94
- return resp
95
-
93
+ try:
94
+ _ = resp.json()
95
+ return resp
96
+ except:
97
+ pass
96
98
  with _cache.lock:
97
99
  _cache.expire_at = 0
98
- time.sleep(0.1)
100
+ time.sleep(0.05)
99
101
  except Exception:
100
102
  with _cache.lock:
101
103
  _cache.expire_at = 0
102
- time.sleep(0.1)
104
+ time.sleep(0.05)
103
105
 
104
106
  # 最终尝试
105
107
  return _original_request(self, method, url, **kwargs)
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.4
2
+ Name: akshare-proxy-patch
3
+ Version: 0.2.9
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/cheapproxy/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`、`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.8
33
+ ```
34
+
35
+ ## 使用方法
36
+
37
+ `akshare` 和 `efinance` 使用方式一致,在文件顶部添加2行代码即可,无需其他额外操作。
38
+
39
+ ```
40
+ # python 文件顶部添加2行代码
41
+ import akshare_proxy_patch
42
+
43
+ akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
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
+ ## install_patch 参数说明
58
+
59
+ - 参数1:网关
60
+ - 默认为 `101.201.173.125` 不可修改
61
+ - 参数2:TOKEN
62
+ - 默认为空,每天可免费使用一定次数。如有更多需求,可[点击此处注册](https://ak.cheapproxy.net/dashboard/akshare)申请正式的 `TOKEN`。
63
+ - 参数3:重试次数
64
+ - 默认为30,建议保持不变
65
+
66
+ ## 如何在 aktools 内集成插件?
67
+
68
+ 需要新建一个 `akt.py` 替换官方的启动方式:
69
+
70
+ ```
71
+ # 添加插件
72
+ import akshare_proxy_patch
73
+
74
+ akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
75
+
76
+ # 启动 aktools
77
+ import uvicorn
78
+
79
+ if __name__ == '__main__':
80
+ uvicorn.run(
81
+ "aktools.main:app",
82
+ host="0.0.0.0",
83
+ port=8080,
84
+ reload=False,
85
+ # 根据 CPU 核心数调整,推荐 2×核心数 + 1
86
+ workers=4,
87
+ log_level="info"
88
+ )
89
+ ```
90
+
91
+ 然后执行 `python akt.py` 即可启动并正常使用 `aktools`。
92
+
93
+ ## 我是手动爬取的接口,能集成插件吗?
94
+
95
+ 能。如果您没有使用 `akshare` 或 `efinance`,而是手动调用的接口,只要代码是使用的 `requests`,插件都能 hook 住请求,正常工作。
96
+
97
+ ## 使用问题交流群
98
+
99
+ 如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
100
+
101
+ ![7sEblPiT7tEdCPrA3nEyekVYxsMZDDgy.webp](https://picui.ogmua.cn/s1/2026/03/03/69a64a45bbda0.webp)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "akshare-proxy-patch" # 包名,需在 PyPI 唯一
7
- version = "0.2.7"
7
+ version = "0.2.9"
8
8
  authors = [
9
9
  { name="cheapproxy", email="emezxyj1@gmail.com" },
10
10
  ]
@@ -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.2.7",
8
+ version="0.2.9",
9
9
  author="cheapproxy.net",
10
10
  author_email="emezxyj1@gmail.com",
11
11
  description="AkShare 和 efinance 报错全局Hook",
@@ -1,75 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: akshare-proxy-patch
3
- Version: 0.2.7
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/cheapproxy/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
- 针对 akshare 和 efinance 的插件补丁,自动为东财接口注入代理认证头,从而避免`akshare: stock_zh_a_spot_em`、`efinance: get_realtime_quotes` 等东财 eastmoney 接口报错问题。
23
-
24
- ## 安装
25
-
26
- 1. 将官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 升级到最新
27
-
28
- ```
29
- # akshare 用户
30
- pip install --upgrade akshare
31
-
32
- # efinance 用户
33
- pip install --upgrade efinance
34
- ```
35
-
36
- 2. 安装最新版本的 `akshare-proxy-patch`
37
- ```
38
- pip install akshare-proxy-patch==0.2.7
39
- ```
40
-
41
- 最好默认用国外源,国内源不是最新的,可能没更新
42
-
43
- ## 使用方法
44
-
45
- 1. `akshare` 和 `efinance` 使用方式一致,在文件顶部添加如下代码
46
- ```
47
- # 文件顶部添加
48
- import akshare_proxy_patch
49
-
50
- # 参数1: AUTH_IP
51
- # 参数2: AUTH_TOKEN,默认为空
52
- # 参数3: retry 重试次数,默认30
53
- akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
54
-
55
- # 你的正常业务代码保持不变
56
-
57
- # 假如使用akshare
58
- import akshare as ak
59
- df = ak.stock_zh_a_spot_em()
60
-
61
- # 假如使用 efinance
62
- import efinance as ef
63
- ef.stock.get_realtime_quotes()
64
- ```
65
-
66
- ## 目前Hook的接口域名清单
67
- - fund.eastmoney.com
68
- - push2.eastmoney.com
69
- - push2his.eastmoney.com
70
-
71
- ## 使用问题交流群
72
-
73
- 如遇到部分接口报错,可进群交流:
74
-
75
- ![8jmzvNOjKWFzwNUDW0Xiytcpfr50uMr5.webp](https://cdn.nodeimage.com/i/8jmzvNOjKWFzwNUDW0Xiytcpfr50uMr5.webp)
@@ -1,55 +0,0 @@
1
- # AkShare Proxy Patch
2
- 针对 akshare 和 efinance 的插件补丁,自动为东财接口注入代理认证头,从而避免`akshare: stock_zh_a_spot_em`、`efinance: get_realtime_quotes` 等东财 eastmoney 接口报错问题。
3
-
4
- ## 安装
5
-
6
- 1. 将官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 升级到最新
7
-
8
- ```
9
- # akshare 用户
10
- pip install --upgrade akshare
11
-
12
- # efinance 用户
13
- pip install --upgrade efinance
14
- ```
15
-
16
- 2. 安装最新版本的 `akshare-proxy-patch`
17
- ```
18
- pip install akshare-proxy-patch==0.2.7
19
- ```
20
-
21
- 最好默认用国外源,国内源不是最新的,可能没更新
22
-
23
- ## 使用方法
24
-
25
- 1. `akshare` 和 `efinance` 使用方式一致,在文件顶部添加如下代码
26
- ```
27
- # 文件顶部添加
28
- import akshare_proxy_patch
29
-
30
- # 参数1: AUTH_IP
31
- # 参数2: AUTH_TOKEN,默认为空
32
- # 参数3: retry 重试次数,默认30
33
- akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
34
-
35
- # 你的正常业务代码保持不变
36
-
37
- # 假如使用akshare
38
- import akshare as ak
39
- df = ak.stock_zh_a_spot_em()
40
-
41
- # 假如使用 efinance
42
- import efinance as ef
43
- ef.stock.get_realtime_quotes()
44
- ```
45
-
46
- ## 目前Hook的接口域名清单
47
- - fund.eastmoney.com
48
- - push2.eastmoney.com
49
- - push2his.eastmoney.com
50
-
51
- ## 使用问题交流群
52
-
53
- 如遇到部分接口报错,可进群交流:
54
-
55
- ![8jmzvNOjKWFzwNUDW0Xiytcpfr50uMr5.webp](https://cdn.nodeimage.com/i/8jmzvNOjKWFzwNUDW0Xiytcpfr50uMr5.webp)
@@ -1,75 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: akshare-proxy-patch
3
- Version: 0.2.7
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/cheapproxy/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
- 针对 akshare 和 efinance 的插件补丁,自动为东财接口注入代理认证头,从而避免`akshare: stock_zh_a_spot_em`、`efinance: get_realtime_quotes` 等东财 eastmoney 接口报错问题。
23
-
24
- ## 安装
25
-
26
- 1. 将官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 升级到最新
27
-
28
- ```
29
- # akshare 用户
30
- pip install --upgrade akshare
31
-
32
- # efinance 用户
33
- pip install --upgrade efinance
34
- ```
35
-
36
- 2. 安装最新版本的 `akshare-proxy-patch`
37
- ```
38
- pip install akshare-proxy-patch==0.2.7
39
- ```
40
-
41
- 最好默认用国外源,国内源不是最新的,可能没更新
42
-
43
- ## 使用方法
44
-
45
- 1. `akshare` 和 `efinance` 使用方式一致,在文件顶部添加如下代码
46
- ```
47
- # 文件顶部添加
48
- import akshare_proxy_patch
49
-
50
- # 参数1: AUTH_IP
51
- # 参数2: AUTH_TOKEN,默认为空
52
- # 参数3: retry 重试次数,默认30
53
- akshare_proxy_patch.install_patch("101.201.173.125", "", 30)
54
-
55
- # 你的正常业务代码保持不变
56
-
57
- # 假如使用akshare
58
- import akshare as ak
59
- df = ak.stock_zh_a_spot_em()
60
-
61
- # 假如使用 efinance
62
- import efinance as ef
63
- ef.stock.get_realtime_quotes()
64
- ```
65
-
66
- ## 目前Hook的接口域名清单
67
- - fund.eastmoney.com
68
- - push2.eastmoney.com
69
- - push2his.eastmoney.com
70
-
71
- ## 使用问题交流群
72
-
73
- 如遇到部分接口报错,可进群交流:
74
-
75
- ![8jmzvNOjKWFzwNUDW0Xiytcpfr50uMr5.webp](https://cdn.nodeimage.com/i/8jmzvNOjKWFzwNUDW0Xiytcpfr50uMr5.webp)