Artifactory PyPI代理缓存过期致pip安装失败,为何pip不触发更新?
pip install Trigger Artifactory Upstream Refresh When PyPI Proxy Cache Expires? Let me break down what's happening here and why you're seeing this discrepancy between pip and curl/browser requests.
The Core Issue: Request Path & Artifactory Cache Handling Differences
Your problem boils down to how Artifactory handles two distinct types of requests related to PyPI packages, and how pip interacts with those endpoints compared to direct curl/browser calls:
pip's Request Flow: When you runpip install -i https://myartifactory.net/api/pypi/virt/simple requests,pipis querying the PyPI Simple API endpoint (/api/pypi/virt/simple/requests/). This endpoint returns a list of available package versions formatted for pip to parse.Direct
curl/Browser Requests: When you hithttps://myartifactory.net/virt/.pypi/requests.html, you're accessing Artifactory's internal package details page, which is a different endpoint than the Simple API.
Artifactory's proxy cache treats these two endpoints differently when cached content expires:
- For the
.pypi/module_name.htmlendpoint: When the cached entry expires, Artifactory detects the stale content and automatically triggers a refresh from the upstream PyPI repository. This updates the cache with the latest package data. - For the Simple API
/simple/module_name/endpoint: By default, Artifactory may not automatically refresh the cached index entry when it expires. Instead, it returns the stale (empty or incomplete) index topip, which then interprets this as "no matching versions found."
Additional Factor: Request Headers
Another possible angle is the request headers sent by pip vs. curl:
pipsends specific cache-related headers (likeIf-Modified-SinceorCache-Control: max-age=0) when querying the Simple API. In some Artifactory configurations, these headers can cause the system to return a 404 or stale data instead of triggering an upstream refresh for expired cache entries.curland browsers typically send simpler headers, which don't trigger this restrictive behavior, prompting Artifactory to refresh the cache immediately.
Fixes to Resolve This
Here are actionable steps to make pip install trigger upstream refreshes automatically when cache expires:
Adjust Proxy Cache Expiration Settings
In your Artifactory PyPI proxy repository settings, look for options related to cache refresh on expiration. Enable the setting that tells Artifactory to fetch fresh content from upstream when cached data is stale, rather than returning a 404 or stale index. You can also tweak the cache TTL (time-to-live) values to match your update frequency needs—longer TTLs mean fewer refreshes, but shorter TTLs keep your cache more up-to-date.Configure Virtual Repository Index Refresh
For your virtual repository, ensure that the index refresh interval is set to a reasonable value. This ensures the combined index (from proxy + private repos) is periodically updated, even if individual proxy cache entries haven't expired yet.Force
pipto Bypass Local Cache (Quick Workaround)
While not a long-term fix, runningpip install --no-cache-dir -i https://myartifactory.net/api/pypi/virt/simple requestscan forcepipto ignore its local cache and re-query Artifactory, which may help if the issue is partially due to pip's local caching.Verify Artifactory Proxy Configuration
Double-check that your proxy repository has the correct upstream PyPI URL set, and that Artifactory has network access to reach it. If there's a connectivity issue, Artifactory can't refresh the cache even when triggered.
内容的提问来源于stack exchange,提问作者VanesBee

