Skip to content

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Oct 3, 2025

Solve huggingface/transformers#41301 reported by @jerryzh168.

The root cause of this issue was when using a custom transport, the proxy env variables are not used by httpx even if trust_env=True. This is the case since encode/httpx#1122. We were using custom Transport in order to handle HF_HUB_OFFLINE env variable (i.e. raise exception if attempt to make an HTTP call) and add custom request id header to help with debugging.

The workaround in this PR is to use event_hooks instead. We are still catching offline mode + adding debug logs at runtime but don't use custom transport anymore. I've added a regression test to check that HTTP_PROXY/HTTPS_PROXY are correctly read from env.

Note: there is a drawback to this PR. We do not catch any httpx.RequestErrors anymore to add the request id to the error message itself. This is not possible to do without a custom Transport. In practice it's not much of an issue because the request id is added back by hf_raise_for_status. The only regression is if an error happens before the server respond (i.e. a readtimeout or connection error), in which case we won't have a request id in the error message. The benefits of this PR still outweigh this drawback IMO.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fix looks good to me! 👍 okay to merge once the test is fixed

Co-authored-by: célina <hanouticelina@gmail.com>
@Wauplin Wauplin merged commit 6af2baa into v1.0-release Oct 7, 2025
14 of 18 checks passed
@Wauplin Wauplin deleted the fix-environment-variable-proxy-not-used branch October 7, 2025 13:43
@Wauplin Wauplin mentioned this pull request Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants