I am using Picasso 2.5.2 in my application. It works well, but can't load pictures from one of third-party server. When I try to load pictures from this site I get this error:
java.net.UnknownServiceException: CLEARTEXT communication not enabled for client
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:98)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:196)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:132)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:101)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
at okhttp3.RealCall.execute(RealCall.java:63)
at com.jakewharton.picasso.OkHttp3Downloader.load(OkHttp3Downloader.java:136)
at com.squareup.picasso.NetworkRequestHandler.load(NetworkRequestHandler.java:47)
at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:206)
at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
When I open this image in browser it load successfully. URL looks like http://somesite.com/path/to/file/123456.jpg
. Is it Picasso bug? How to fix it?
Is it Picasso bug?
I don't think so. OkHttp appears to block non-SSL communications by default. I haven't done a plain-text HTTP request with OkHttp in ages, but that's what I'm seeing from my examination of the code that relates to that error message.
How to fix it?
Use an https
URL.
If some diabolical madman is threatening to blow up a small city unless you use plain http
, configure the OkHttpClient
via its Builder
, including a call to connectionSpecs()
to indicate what sorts of HTTP connections you are willing to support. For example:
.connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT))
would allow "modern TLS" (not exactly certain what qualifies) and plain HTTP.
Then, use that OkHttpClient
for Picasso, as well as for anything that you are doing directly using OkHttp.
I have searched your problems. And I think you have problem with okhttp3 like the issue at https://github.com/fabric8io/kubernetes-client/issues/498 - problem with authentication connection. You can try to work around by custom your downloader of Picasso by:
// create Picasso.Builder object
Picasso.Builder picassoBuilder = new Picasso.Builder(context);
// let's change the standard behavior before we create the Picasso instance
// for example, let's switch out the standard downloader for the OkHttpClient
picassoBuilder.downloader(new OkHttpDownloader(new OkHttpClient()));
// or you can try
(picassoBuilder.downloader(
new OkHttpDownloader(
UnsafeOkHttpClient.getUnsafeOkHttpClient()
)
);)
// Picasso.Builder creates the Picasso object to do the actual requests
Picasso picasso = picassoBuilder.build();
Now you can use your picasso to load your image.
picasso
.load(linktoimage)
.into(imageView3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With