akshare-proxy-patch 0.1.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.
File without changes
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: akshare-proxy-patch
3
+ Version: 0.1.0
4
+ Summary: 针对 AkShare 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `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: akshare
16
+ Requires-Dist: requests
17
+ Dynamic: author
18
+ Dynamic: home-page
19
+ Dynamic: license-file
20
+ Dynamic: requires-python
21
+
22
+ # AkShare Proxy Patch
23
+ 针对 AkShare 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
24
+
25
+ ## 安装
26
+
27
+ ```
28
+ pip install akshare-proxy-patch -i https://mirrors.aliyun.com/pypi/simple
29
+ ```
30
+
31
+ ## 使用
32
+
33
+ 1. 访问 https://cheapproxy.net 联系客服,获取授权码 `AUTH_TOKEN`
34
+
35
+ 2. 在使用 akshare 文件顶部添加下面的内容
36
+ ```
37
+ import akshare_proxy_patch
38
+
39
+ akshare_proxy_patch.install_patch("AUTH_TOKEN")
40
+
41
+
42
+ # import akshare as ak
43
+ # df = ak.stock_zh_a_spot_em()
44
+ # 你的其他代码......
45
+ ```
@@ -0,0 +1,24 @@
1
+ # AkShare Proxy Patch
2
+ 针对 AkShare 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
3
+
4
+ ## 安装
5
+
6
+ ```
7
+ pip install akshare-proxy-patch -i https://mirrors.aliyun.com/pypi/simple
8
+ ```
9
+
10
+ ## 使用
11
+
12
+ 1. 访问 https://cheapproxy.net 联系客服,获取授权码 `AUTH_TOKEN`
13
+
14
+ 2. 在使用 akshare 文件顶部添加下面的内容
15
+ ```
16
+ import akshare_proxy_patch
17
+
18
+ akshare_proxy_patch.install_patch("AUTH_TOKEN")
19
+
20
+
21
+ # import akshare as ak
22
+ # df = ak.stock_zh_a_spot_em()
23
+ # 你的其他代码......
24
+ ```
@@ -0,0 +1,39 @@
1
+ import requests
2
+ import time
3
+ from requests.adapters import HTTPAdapter
4
+
5
+ original_send = HTTPAdapter.send
6
+
7
+
8
+ def install_patch(auth_token):
9
+ def patched_send(self, request, **kwargs):
10
+ url = request.url
11
+ if "82.push2.eastmoney.com" not in url and "push2his.eastmoney.com" not in url:
12
+ return original_send(self, request, **kwargs)
13
+ for i in range(60):
14
+ try:
15
+ with requests.Session() as s:
16
+ HTTPAdapter.send = original_send
17
+ auth_url = "https://akshare.cheapproxy.net/api/akshare-auth"
18
+ auth_res = s.get(
19
+ auth_url, params={"token": auth_token}, timeout=5
20
+ ).json()
21
+ if not auth_res["ua"]:
22
+ print("请先登录 https://cheapproxy.net 联系客服获取授权码")
23
+ return None
24
+
25
+ HTTPAdapter.send = patched_send
26
+ request.headers["User-Agent"] = auth_res["ua"]
27
+ cookie_str = f"nid18={auth_res['nid18']}; nid18_create_time={auth_res['nid18_create_time']}"
28
+ request.headers["Cookie"] = cookie_str
29
+ proxy = auth_res["proxy"]
30
+ kwargs["proxies"] = {"http": proxy, "https": proxy}
31
+ kwargs["timeout"] = kwargs.get("timeout") or 15
32
+ return original_send(self, request, **kwargs)
33
+ except Exception as e:
34
+ time.sleep(0.5)
35
+ HTTPAdapter.send = patched_send
36
+
37
+ return original_send(self, request, **kwargs)
38
+
39
+ HTTPAdapter.send = patched_send
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: akshare-proxy-patch
3
+ Version: 0.1.0
4
+ Summary: 针对 AkShare 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `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: akshare
16
+ Requires-Dist: requests
17
+ Dynamic: author
18
+ Dynamic: home-page
19
+ Dynamic: license-file
20
+ Dynamic: requires-python
21
+
22
+ # AkShare Proxy Patch
23
+ 针对 AkShare 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
24
+
25
+ ## 安装
26
+
27
+ ```
28
+ pip install akshare-proxy-patch -i https://mirrors.aliyun.com/pypi/simple
29
+ ```
30
+
31
+ ## 使用
32
+
33
+ 1. 访问 https://cheapproxy.net 联系客服,获取授权码 `AUTH_TOKEN`
34
+
35
+ 2. 在使用 akshare 文件顶部添加下面的内容
36
+ ```
37
+ import akshare_proxy_patch
38
+
39
+ akshare_proxy_patch.install_patch("AUTH_TOKEN")
40
+
41
+
42
+ # import akshare as ak
43
+ # df = ak.stock_zh_a_spot_em()
44
+ # 你的其他代码......
45
+ ```
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ akshare_proxy_patch/__init__.py
6
+ akshare_proxy_patch.egg-info/PKG-INFO
7
+ akshare_proxy_patch.egg-info/SOURCES.txt
8
+ akshare_proxy_patch.egg-info/dependency_links.txt
9
+ akshare_proxy_patch.egg-info/requires.txt
10
+ akshare_proxy_patch.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ akshare
2
+ requests
@@ -0,0 +1 @@
1
+ akshare_proxy_patch
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "akshare-proxy-patch" # 包名,需在 PyPI 唯一
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name="cheapproxy", email="emezxyj1@gmail.com" },
10
+ ]
11
+ description = "针对 AkShare 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。"
12
+ readme = "README.md"
13
+ requires-python = ">=3.7"
14
+ dependencies = [
15
+ "akshare",
16
+ "requests",
17
+ ]
18
+ classifiers = [
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent",
22
+ ]
23
+
24
+ [project.urls]
25
+ "Homepage" = "https://github.com/cheapproxy/akshare-proxy-patch"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,26 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="akshare-proxy-patch", # 包名,用户 pip install 时的名称
8
+ version="0.1.0", # 版本号
9
+ author="cheapproxy.net",
10
+ author_email="emezxyj1@gmail.com",
11
+ description="AkShare 报错全局Hook",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ url="https://github.com/helloyie/akshare-proxy-patch", # 项目主页
15
+ packages=find_packages(), # 自动查找项目中的包
16
+ classifiers=[
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ ],
21
+ python_requires=">=3.6", # 对 Python 版本的要求
22
+ install_requires=[ # 核心依赖:安装此包时会自动安装这些
23
+ "requests",
24
+ ],
25
+ include_package_data=True,
26
+ )