Environment variable based proxy is not working due to aiohttp default settings when using `kimi login`
What version of Kimi Code CLI is running?
kimi, version 1.13.0
Which open platform/subscription were you using?
Kimi Code
Which model were you using?
kimi-for-coding
What platform is your computer?
Linux 5.15.0-89-generic x86_64 x86_64
What issue are you seeing?
I'm using kimi-cli on remote machine, and I must using https proxy to access internet. When I running command kimi login, it hangs for a while and then show error:
Login failed: Connection timeout to host https://auth.kimi.com/api/oauth/device_authorization
What steps can reproduce the bug?
In a container with only https proxy url based internet access, just run kimi login.
What is the expected behavior?
No response
Additional information
After I do some debugging, I found the hang problem is caused by the following code:
https://github.com/MoonshotAI/kimi-cli/blob/1.13.0/src/kimi_cli/auth/oauth.py#L314-L321
aiohttp session post a request to the url, but the default param trust_env of aiohttp.ClientSession is False, see
https://github.com/MoonshotAI/kimi-cli/blob/1.13.0/src/kimi_cli/utils/aiohttp.py#L12 and
https://github.com/aio-libs/aiohttp/blob/50241d68c1133875ad98a6eadbc71d03ea4b2e0c/aiohttp/client.py#L331. It would not respect environment variable based proxy url setting such as HTTPS_PROXY or https_proxy.
#762 there have a pr to resolve this problem.
#762 there have a pr to resolve this problem.
Thanks for your reply, but it would not help in my case, I just test it.
Following code can solve the problem, but I don't know if it's suitable for this repo:
# kimi_cli.utils.aiohttp
# ...
def new_client_session() -> aiohttp.ClientSession:
return aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(ssl=_ssl_context))
Following code can solve the problem, but I don't know if it's suitable for this repo:
kimi_cli.utils.aiohttp
...
def new_client_session() -> aiohttp.ClientSession: return aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(ssl=_ssl_context))
I think should add it. Welcome to pr to fixed this problem.
@xiaoju111a I have already made a PR #1236, but I don't know how to add a test on it. I just ask copilot to work on it.
@xiaoju111a I have already make a PR #1236, but I don't know how to add a test on it. I just ask copilot to work on it.
No additional test is required for this change.
@xiaoju111a How to merge this PR #1236 ? No one is assigned to review and merge it.
Meet same problem
Meet same problem
@lakako You can try #1236, this fix login problems on my machine. No maintainer responds to review and merge it into main. Waiting for someone's help.
@xiaoju111a Hi! Sorry to follow upβare you the maintainer of this project? I'm wondering if this PR is planned to be merged into main, or if there's anything blocking it. If someone else should review this, could you tag them here? Thanks!
The new_client_session() in utils/aiohttp.py doesn't set trust_env=True, so aiohttp.ClientSession ignores HTTP_PROXY/HTTPS_PROXY environment variables by default. One-line fix: add trust_env=True to the constructor.
The
new_client_session()inutils/aiohttp.pydoesn't settrust_env=True, soaiohttp.ClientSessionignoresHTTP_PROXY/HTTPS_PROXYenvironment variables by default. One-line fix: addtrust_env=Trueto the constructor.
@Br1an67 what's the difference between PR #1465 and PR #1236 ? I wrote #1236 and I don't know how to contact with maintainer to merge this fix. If you have connections, please merge #1465 ASAP.
@CyCle1024 Sorry about the duplicate! I didn't check existing PRs before submitting β my bad. Your #1236 is more complete with changelog and docs updates. I'll close #1465 in favor of yours. Hope it gets merged soon π
@CyCle1024 Sorry about the duplicate! I didn't check existing PRs before submitting β my bad. Your #1236 is more complete with changelog and docs updates. I'll close #1465 in favor of yours. Hope it gets merged soon π
@Br1an67 Never mind. I just hope that we can merge it, for now I don't see any chance and I don't know why.