swagger-codegen
swagger-codegen copied to clipboard
[Python] generator doesn't support SOCKS proxy
Description
Python generation doesn't include a SOCKS proxy connection manager in the rest connector
Swagger-codegen version
2.4.0
Suggest a fix/enhancement
In the generated python code, rest.py in the proxy configuration switch it should detect if the proxy url starts with "socks" and switch between SOCKSProxyManager() and ProxyManager(). A good example is in the Python library "requests". requests.adapters.HTTPAdapter().proxy_manager_for()
trivial to fix ...
patch for generated code
https://github.com/milahu/gitea-client-python/commit/4f3d6e2d9d25edce4a99ea7cf13c6c4baa061e08
commit 4f3d6e2d9d25edce4a99ea7cf13c6c4baa061e08
Author: Milan Hauth <[email protected]>
Date: Sat Jul 27 20:20:46 2024 +0200
add pysocks
diff --git a/gitea_client/rest.py b/gitea_client/rest.py
index 9d4e85a..3b8ad7e 100644
--- a/gitea_client/rest.py
+++ b/gitea_client/rest.py
@@ -83,7 +83,12 @@ class RESTClientObject(object):
# https pool manager
if configuration.proxy:
- self.pool_manager = urllib3.ProxyManager(
+ if configuration.proxy.startswith("http"):
+ ProxyManager = urllib3.ProxyManager
+ else:
+ from urllib3.contrib.socks import SOCKSProxyManager
+ ProxyManager = SOCKSProxyManager
+ self.pool_manager = ProxyManager(
num_pools=pools_size,
maxsize=maxsize,
cert_reqs=cert_reqs,
diff --git a/requirements.txt b/requirements.txt
index bafdc07..02d5ee6 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,3 +3,4 @@ six >= 1.10
python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.15.1
+pysocks
diff --git a/setup.py b/setup.py
index f10ec3c..c06d511 100644
--- a/setup.py
+++ b/setup.py
@@ -25,6 +25,7 @@ REQUIRES = [
"certifi>=2017.4.17",
"python-dateutil>=2.1",
"six>=1.10",
+ "pysocks",
"urllib3>=1.23"
]
error was
File "gitea_client/rest.py", line 94, in __init__
self.pool_manager = urllib3.ProxyManager(
^^^^^^^^^^^^^^^^^^^^
File "urllib3/poolmanager.py", line 567, in __init__
raise ProxySchemeUnknown(proxy.scheme)
urllib3.exceptions.ProxySchemeUnknown: Proxy URL had unsupported scheme socks5h, should use http:// or https://