Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picasso: UnknownServiceException: CLEARTEXT communication not enabled for client

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?

like image 224
BArtWell Avatar asked Jan 09 '17 15:01

BArtWell


2 Answers

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.

like image 198
CommonsWare Avatar answered Oct 14 '22 21:10

CommonsWare


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);
like image 34
RoShan Shan Avatar answered Oct 14 '22 22:10

RoShan Shan