pytool-proxy-fix 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.
- pytool_proxy_fix-0.1.0/LICENSE +1 -0
- pytool_proxy_fix-0.1.0/PKG-INFO +56 -0
- pytool_proxy_fix-0.1.0/proxy_fix/__init__.py +0 -0
- pytool_proxy_fix-0.1.0/proxy_fix/fix_urllib_https.py +56 -0
- pytool_proxy_fix-0.1.0/pyproject.toml +3 -0
- pytool_proxy_fix-0.1.0/pytool_proxy_fix.egg-info/PKG-INFO +56 -0
- pytool_proxy_fix-0.1.0/pytool_proxy_fix.egg-info/SOURCES.txt +10 -0
- pytool_proxy_fix-0.1.0/pytool_proxy_fix.egg-info/dependency_links.txt +1 -0
- pytool_proxy_fix-0.1.0/pytool_proxy_fix.egg-info/entry_points.txt +2 -0
- pytool_proxy_fix-0.1.0/pytool_proxy_fix.egg-info/top_level.txt +1 -0
- pytool_proxy_fix-0.1.0/setup.cfg +4 -0
- pytool_proxy_fix-0.1.0/setup.py +26 -0
|
@@ -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.
|
|
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,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,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
proxy_fix/__init__.py
|
|
5
|
+
proxy_fix/fix_urllib_https.py
|
|
6
|
+
pytool_proxy_fix.egg-info/PKG-INFO
|
|
7
|
+
pytool_proxy_fix.egg-info/SOURCES.txt
|
|
8
|
+
pytool_proxy_fix.egg-info/dependency_links.txt
|
|
9
|
+
pytool_proxy_fix.egg-info/entry_points.txt
|
|
10
|
+
pytool_proxy_fix.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
proxy_fix
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="pytool-proxy-fix",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
description="Fix urllib for python 3.7/3.8",
|
|
7
|
+
long_description=open("README.MD").read(),
|
|
8
|
+
long_description_content_type="text/markdown",
|
|
9
|
+
author="kites262",
|
|
10
|
+
author_email="kites262@github.com",
|
|
11
|
+
url="https://github.com/kites262/tool-fix-urllib",
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
classifiers=[
|
|
14
|
+
"Programming Language :: Python :: 3.7",
|
|
15
|
+
"Programming Language :: Python :: 3.8",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
],
|
|
19
|
+
python_requires=">=3.7, <3.9",
|
|
20
|
+
entry_points={
|
|
21
|
+
"console_scripts": [
|
|
22
|
+
"pytool-proxy-fix=tool_fix_urllib.main:main_fix_urllib",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
license="MIT",
|
|
26
|
+
)
|