-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
I was trying to use this library with http proxy.
However, if I set the 'proxy' configuration(like below script) and run the program, ka.client.CoreV1Api()
raises TypeError.
This is the script(almost same as README.md
sample):
import asyncio
import kubernetes_asyncio as ka
async def main():
await ka.config.load_kube_config()
# below 3 lines are main change from `README.md` sample.
conf = ka.client.Configuration()
conf.proxy = 'http://your_http_proxy'
ka.client.Configuration.set_default(conf)
v1 = ka.client.CoreV1Api() # This raises exception.
print("Listing pods with their IPs:")
ret = await v1.list_pod_for_all_namespaces()
for i in ret.items:
print(i.status.pod_ip, i.metadata.namespace, i.metadata.name)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
The output is:
Exception ignored in: <bound method ClientSession.__del__ of <aiohttp.client.ClientSession object at 0x7fa97bb3fc88>>
Traceback (most recent call last):
File "/home/ta-ono/.virtualenvs/dev-ka/lib/python3.6/site-packages/aiohttp/client.py", line 302, in __del__
if not self.closed:
File "/home/ta-ono/.virtualenvs/dev-ka/lib/python3.6/site-packages/aiohttp/client.py", line 916, in closed
return self._connector is None or self._connector.closed
AttributeError: 'ClientSession' object has no attribute '_connector'
Traceback (most recent call last):
File "test.py", line 26, in <module>
loop.run_until_complete(main())
File "/usr/lib64/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "test.py", line 16, in main
v1 = ka.client.CoreV1Api()
File "/home/ta-ono/programs/kubernetes_asyncio/kubernetes_asyncio/client/api/core_v1_api.py", line 32, in __init__
api_client = ApiClient()
File "/home/ta-ono/programs/kubernetes_asyncio/kubernetes_asyncio/client/api_client.py", line 72, in __init__
self.rest_client = rest.RESTClientObject(configuration)
File "/home/ta-ono/programs/kubernetes_asyncio/kubernetes_asyncio/client/rest.py", line 76, in __init__
proxy=configuration.proxy
TypeError: __init__() got an unexpected keyword argument 'proxy'
Exception ignored in: <bound method RESTClientObject.__del__ of <kubernetes_asyncio.client.rest.RESTClientObject object at 0x7fa97bb3f470>>
Traceback (most recent call last):
File "/home/ta-ono/programs/kubernetes_asyncio/kubernetes_asyncio/client/rest.py", line 84, in __del__
AttributeError: 'RESTClientObject' object has no attribute 'pool_manager'
I think proxy
argument should be passed to aiohttp.ClientSession.request
instead of aiohttp.ClientSession
.
I could run the above script by changing kubernetes_asyncio.client.rest.RESTClientObject
.
The change is:
(dev-ka) [ta-ono@kubernetes_asyncio]$ git diff
diff --git a/kubernetes_asyncio/client/rest.py b/kubernetes_asyncio/client/rest.py
index 69bba34a..5a71b894 100644
--- a/kubernetes_asyncio/client/rest.py
+++ b/kubernetes_asyncio/client/rest.py
@@ -69,16 +69,12 @@ class RESTClientObject(object):
ssl_context=ssl_context
)
+ self.proxy = configuration.proxy
+
# https pool manager
- if configuration.proxy:
- self.pool_manager = aiohttp.ClientSession(
- connector=connector,
- proxy=configuration.proxy
- )
- else:
- self.pool_manager = aiohttp.ClientSession(
- connector=connector
- )
+ self.pool_manager = aiohttp.ClientSession(
+ connector=connector
+ )
def __del__(self):
asyncio.ensure_future(self.pool_manager.close())
@@ -168,6 +164,7 @@ class RESTClientObject(object):
declared content type."""
raise ApiException(status=0, reason=msg)
+ args['proxy'] = self.proxy
r = await self.pool_manager.request(**args)
if _preload_content:
However this change doesn't pass pytest via http proxy.
So I'm not sure this is correct.
Thanks.
Metadata
Metadata
Assignees
Labels
No labels