bumptech/glide · error · HttpException
Failed to connect or obtain data
Error message
Failed to connect or obtain data
What it means
HttpUrlFetcher calls connect() and getInputStream() on the HttpURLConnection. If either operation throws an IOException (connection refused, timeout, DNS failure, network unreachable), it is wrapped in an HttpException with the message 'Failed to connect or obtain data'. The HTTP status code is extracted from the connection if available, otherwise INVALID_STATUS_CODE (-1) is used.
Source
Thrown at library/src/main/java/com/bumptech/glide/load/data/HttpUrlFetcher.java:98
// See http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html.
try {
if (lastUrl != null && url.toURI().equals(lastUrl.toURI())) {
throw new HttpException("In re-direct loop", INVALID_STATUS_CODE);
}
} catch (URISyntaxException e) {
// Do nothing, this is best effort.
}
}
urlConnection = buildAndConfigureConnection(url, headers);
try {
// Connect explicitly to avoid errors in decoders if connection fails.
urlConnection.connect();
// Set the stream so that it's closed in cleanup to avoid resource leaks. See #2352.
stream = urlConnection.getInputStream();
} catch (IOException e) {
throw new HttpException(
"Failed to connect or obtain data", getHttpStatusCodeOrInvalid(urlConnection), e);
}
if (isCancelled) {
return null;
}
final int statusCode = getHttpStatusCodeOrInvalid(urlConnection);
if (isHttpOk(statusCode)) {
return getStreamForSuccessfulRequest(urlConnection);
} else if (isHttpRedirect(statusCode)) {
String redirectUrlString = urlConnection.getHeaderField(REDIRECT_HEADER_FIELD);
if (TextUtils.isEmpty(redirectUrlString)) {
throw new HttpException("Received empty or null redirect url", statusCode);
}
URL redirectUrl;
try {
redirectUrl = new URL(url, redirectUrlString);View on GitHub (pinned to eb14a895d8)
Solutions
- Verify network connectivity and that the URL is reachable in a browser or via curl
- Increase connection/read timeouts or integrate OkHttp with Glide for finer timeout control
- Add .error() and .fallback() placeholders so the UI degrades gracefully
- Implement retry logic via a custom RequestListener or RetryExecutor
Example fix
// before Glide.with(context).load(url).into(imageView); // after — add error placeholder and longer timeout via OkHttp integration Glide.with(context) .load(url) .error(R.drawable.error_placeholder) .into(imageView);
Defensive patterns
Strategy: retry
Validate before calling
// Check connectivity before attempting image load
private boolean isNetworkAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo active = cm.getActiveNetworkInfo();
return active != null && active.isConnected();
}
if (isNetworkAvailable(context)) {
Glide.with(context).load(url).into(imageView);
} Try / catch
Glide.with(context)
.load(url)
.error(R.drawable.error_placeholder)
.listener(new RequestListener<Drawable>() {
@Override public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
// HttpException with 'Failed to connect or obtain data' surfaces here
Log.w(TAG, "Connection failed for " + model, e);
return false;
}
@Override public boolean onResourceReady(Drawable r, Object m, Target<Drawable> t, DataSource d, boolean i) { return false; }
})
.into(imageView); Prevention
- Check network connectivity before loading remote images
- Integrate OkHttp with Glide for configurable timeouts and connection pooling
- Always provide .error() placeholders for remote loads
- Consider implementing exponential backoff retry for transient network failures
When it happens
Trigger: Network connectivity is unavailable or unreliable. DNS resolution fails for the image host. The server is down or refusing connections. Connection or read timeout exceeded. SSL/TLS handshake failure.
Common situations: Loading images on flaky mobile networks. Loading from a host that is behind a firewall or geo-blocked. Slow servers that exceed Glide's default timeout. HTTPS certificate issues with self-signed or expired certs.
Related errors
- Received empty or null redirect url
- Bad redirect url: {redirectUrlString}
- Http request failed
- Failed to get a response message
- Failed to obtain InputStream
AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14).
Data as JSON: /api/errors/ccc2e0065286ee4d.
Report an issue: GitHub.