kimi-cli icon indicating copy to clipboard operation
kimi-cli copied to clipboard

Environment variable based proxy is not working due to aiohttp default settings when using `kimi login`

Open CyCle1024 opened this issue 9 months ago β€’ 14 comments

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.

CyCle1024 avatar Feb 25 '26 08:02 CyCle1024

#762 there have a pr to resolve this problem.

xiaoju111a avatar Feb 25 '26 08:02 xiaoju111a

#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.

CyCle1024 avatar Feb 25 '26 08:02 CyCle1024

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))

CyCle1024 avatar Feb 25 '26 08:02 CyCle1024

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 avatar Feb 25 '26 08:02 xiaoju111a

@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.

CyCle1024 avatar Feb 25 '26 09:02 CyCle1024

@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 avatar Feb 25 '26 09:02 xiaoju111a

@xiaoju111a How to merge this PR #1236 ? No one is assigned to review and merge it.

CyCle1024 avatar Feb 27 '26 03:02 CyCle1024

Meet same problem

lakako avatar Mar 05 '26 01:03 lakako

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.

CyCle1024 avatar Mar 05 '26 06:03 CyCle1024

@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!

CyCle1024 avatar Mar 09 '26 08:03 CyCle1024

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.

Br1an67 avatar Mar 17 '26 06:03 Br1an67

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.

@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 avatar Mar 17 '26 06:03 CyCle1024

@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 avatar Mar 17 '26 07:03 Br1an67

@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.

CyCle1024 avatar Mar 17 '26 07:03 CyCle1024