pytool-proxy-fix 0.1.0__py3-none-any.whl

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.
proxy_fix/__init__.py ADDED
File without changes
@@ -0,0 +1,56 @@
1
+ import os
2
+ import sys
3
+ import fileinput
4
+
5
+ def get_urllib_path():
6
+ '''根据当前的 Python 环境获取 urllib 模块路径'''
7
+ python_home = sys.prefix # 这是 Python 环境的根目录
8
+ urllib_path = os.path.join(python_home, 'Lib', 'urllib')
9
+
10
+ # 检查 urllib 模块路径是否存在
11
+ if os.path.exists(urllib_path):
12
+ return urllib_path
13
+ else:
14
+ raise FileNotFoundError('Unable to locate the urllib module in the current Python environment.')
15
+
16
+ def fix_urllib_bug():
17
+ '''修复 urllib.request.py 中的 'https' 改为 'http' 的 bug'''
18
+ try:
19
+ urllib_path = get_urllib_path()
20
+
21
+ # 要修改的是 `request.py` 文件
22
+ request_file_path = os.path.join(urllib_path, 'request.py')
23
+
24
+ if not os.path.exists(request_file_path):
25
+ raise FileNotFoundError(f'{request_file_path} does not exist.')
26
+
27
+ bug_fixed = False
28
+ bug_line_number = 0
29
+ bug_line = ''
30
+
31
+ # 使用 fileinput 修改文件内容
32
+ with fileinput.FileInput(request_file_path, inplace=True, backup='.bak') as file:
33
+
34
+ for line in file:
35
+ # 查找并修改目标行
36
+ if "proxies['https'] = 'https://%s' % proxyServer" in line:
37
+ line = line.replace('https://', 'http://') # 修改 https 为 http
38
+ bug_fixed = True
39
+ bug_line_number = file.filelineno()
40
+ bug_line = line
41
+ print(line, end='')
42
+
43
+ if bug_fixed:
44
+ print(f'Bug fix applied successfully in {request_file_path}')
45
+ print(f'Backup file: {request_file_path}.bak')
46
+ print(f'Fixed line#{bug_line_number}: \n---\n{bug_line.strip()}\n---')
47
+ else:
48
+ os.remove(f'{request_file_path}.bak')
49
+ print(f'Bug fix not applied in {request_file_path}')
50
+ print('That means the bug might have been fixed in the current environment.')
51
+ except Exception as e:
52
+ print(f'Error: {e}')
53
+
54
+ def main():
55
+ '''主函数'''
56
+ fix_urllib_bug()
@@ -0,0 +1 @@
1
+ MIT
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.1
2
+ Name: pytool-proxy-fix
3
+ Version: 0.1.0
4
+ Summary: Fix urllib for python 3.7/3.8
5
+ Home-page: https://github.com/kites262/tool-fix-urllib
6
+ Author: kites262
7
+ Author-email: kites262@github.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3.7
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.7, <3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # pytool-proxy-fix
18
+
19
+ A simple tool to fix the bug when `pip install` fails due to SSL errors in Python `3.7`, `3.8`.
20
+
21
+ Error message look like this:
22
+
23
+ ```bash
24
+ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLZeroReturnError(6, '
25
+ TLS/SSL connection has been closed (EOF)
26
+ ```
27
+
28
+ When the system proxy is set while `pip.ini` is not configured, `pip install` may fail with SSL errors.
29
+
30
+ This tool will fix the issue.
31
+
32
+ ## Requirements
33
+
34
+ This tool is **ONLY** for Python `3.7`, `3.8`: Tool will edit a specific file in the Python standard library.
35
+
36
+ For other versions, the problem may **VARIES**. However, try to add a `pip.ini` for the proxy settings is never a bad idea.
37
+
38
+ Refer to [This Blog Post](https://kites.cc/p/python-pip-ssl-proxy-error/)
39
+
40
+ ## Installation
41
+
42
+ You can install this package using pip:
43
+
44
+ ```bash
45
+ pip install pytool-proxy-fix
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ Once installed, you can use the tool by running the following command:
51
+
52
+ ```bash
53
+ pytool-proxy-fix
54
+ ```
55
+
56
+ The tool will automatically fix the issue.
@@ -0,0 +1,8 @@
1
+ proxy_fix/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ proxy_fix/fix_urllib_https.py,sha256=roJN_AO8TJps6xGWnSSbIQWc70gBicXA_dAbIuC1HG4,2165
3
+ pytool_proxy_fix-0.1.0.dist-info/LICENSE,sha256=5dz_6Da27IpY5JJBm1UOZfuMvcMIUDl55drLM6x-o7c,3
4
+ pytool_proxy_fix-0.1.0.dist-info/METADATA,sha256=ynMc-IED_1X9R_U67n_kjkGmS01TvkusZI5sELUf0YQ,1634
5
+ pytool_proxy_fix-0.1.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ pytool_proxy_fix-0.1.0.dist-info/entry_points.txt,sha256=LKEb9L85-Bm25_rkxAtwFqapaBlRtCrs50GzRfchnYI,74
7
+ pytool_proxy_fix-0.1.0.dist-info/top_level.txt,sha256=E3Rux2NF_OHNM8skTx1MJoMlIE9L7OjPGUo5ylMi0ok,10
8
+ pytool_proxy_fix-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pytool-proxy-fix = tool_fix_urllib.main:main_fix_urllib
@@ -0,0 +1 @@
1
+ proxy_fix