Picasso: Picasso not loading images from https urls

Created on 8 May 2014  Â·  23Comments  Â·  Source: square/picasso

Hi,

I'm running a simple test where I try to get a photo from Flickr like so:

Picasso.with(context)
    .load("https://farm6.staticflickr.com/5294/5460063960_1ef2d5c216_o.jpg")
            .resize(width, height)
            .into(target);

Problem is, if I use https, the loading fails with a timeout. It doesn't happen if I use http instead. Is there any config setting I could use or something else that can be done or that I am missing? Below is the stack trace.

Thank you!

java.net.SocketTimeoutException: Read timed out
at com.squareup.okhttp.internal.spdy.SpdyStream$SpdyDataSource.waitUntilReadable(SpdyStream.java:417)
at com.squareup.okhttp.internal.spdy.SpdyStream$SpdyDataSource.read(SpdyStream.java:368)
at com.squareup.okhttp.internal.http.SpdyTransport$SpdySource.read(SpdyTransport.java:268)
at com.squareup.okhttp.internal.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)
at java.io.InputStream.read(InputStream.java:163)
at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142)
at java.io.BufferedInputStream.read(BufferedInputStream.java:309)
at com.squareup.picasso.MarkableInputStream.read(MarkableInputStream.java:138)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:664)
at com.squareup.picasso.NetworkBitmapHunter.decodeStream(NetworkBitmapHunter.java:108)
at com.squareup.picasso.NetworkBitmapHunter.decode(NetworkBitmapHunter.java:60)
at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:123)
at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:83)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:306)

Most helpful comment

We charge $10 to enable HTTPS.

On Sun, May 10, 2015, 9:20 AM tamawy [email protected] wrote:

Use Universal Image Loader instead. It supports HTTPS by default
https://github.com/nostra13/Android-Universal-Image-Loader

—
Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/500#issuecomment-100640546.

All 23 comments

What version of OkHttp are you using?

Version 1.5.4. OkHttp actually works with https when I access the Flickr API at https://api.flickr.com/. Just when I try to get the photo itself using https that it fails.

This might be a bug in the SPDY support of OkHttp and how Flickr's servers behave. You can disable SPDY with this:

OkHttpClient client = new OkHttpClient();
client.setProtocols(Arrays.asList(Protocol.HTTP_11));
Picasso picasso = new Picasso.Builder(context)
    .downloader(new OkDownloader(client))
    .build();

Downside here is that you have to carry that picasso reference around your app rather than using Picasso.with(context).

We should really provide a way to configure the global singleton...

That seemed to do the trick. In my case I just need that reference once so it's not a major concern. Thank you so much for the quick response and support!

Hi, I'm finding de same problem but with Picasso 2.4.0. I'm doing this:

OkHttpClient client = new OkHttpClient();
client.setProtocols(Arrays.asList(Protocol.HTTP_1_1));
final Picasso picasso = new Picasso.Builder(context)
.downloader(new OkHttpDownloader(client))
.build();


picasso.with(context).load(
String.format(GET_PROFILE_IMAGE, jid)).noFade()
.into(avatar);

as OkDownloader no longer exists :/ i don't know how to face it thx

Use Universal Image Loader instead. It supports HTTPS by default
https://github.com/nostra13/Android-Universal-Image-Loader

We charge $10 to enable HTTPS.

On Sun, May 10, 2015, 9:20 AM tamawy [email protected] wrote:

Use Universal Image Loader instead. It supports HTTPS by default
https://github.com/nostra13/Android-Universal-Image-Loader

—
Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/500#issuecomment-100640546.

I believe that the Universal Image Loader does not perform all the image downloading in one session. It starts HTTPS session for each image. Which is something make the image loading is extremely slow. Are you following the same approach? And is that price is one time payment for the commercial use?

I was making a joke.

Picasso does not have an HTTP client inside of it so saying that is "supports HTTPS" means little. When you pass in a url (whether it has a scheme of http:// or https://) we pass that along to the most appropriate HTTP client there is. Maybe that's java.net.HttpURLConnection. Maybe it's that sexy bundle of bytecode OkHttp. The bottom line is that whatever the scheme is we just let the HTTP client handle it. Any problems you are having with http:// vs https:// are in the configuration of the client, not Picasso.

First, I'd like to thank you for your response. Second, don't make jokes
with me again :D. Third, someone on StackOverFlow asked a question about
the same issue and on of the answer was recommending to him to implement
TrustAllCerts and initialize the instance with it (
http://stackoverflow.com/a/26398617/1364896). I will expect that this is
right, but if you think I should do something else or something missing,
let me know please. Thanks again.

BTW, you, personally, were the center of a conversation between some
Android developers few weeks ago in Android development conference in Dubai
:)

On Thu, May 21, 2015 at 6:53 AM, Jake Wharton [email protected]
wrote:

I was making a joke.

Picasso does not have an HTTP client inside of it so saying that is
"supports HTTPS" means little. When you pass in a url (whether it has a
scheme of http:// or https://) we pass that along to the most appropriate
HTTP client there is. Maybe that's java.net.HttpURLConnection. Maybe it's
that sexy bundle of bytecode OkHttp. The bottom line is that whatever the
scheme is we just let the HTTP client handle it. Any problems you are
having with http:// vs https:// are in the configuration of the client,
not Picasso.

—
Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/500#issuecomment-104108875.

Regards,

Sami El-Tamawy
Software engineer
Insydo
Dubai, UAE
Mobile: (+971) 52565 9772
Skypid: a.s.tamawy

@JakeWharton your solution was helpful. @tamawy take it easy on @JakeWharton.

I have the same issue Picasso did not work with Okhttp and URL "https"
My dependencies:
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.4.0'
Any ideas?

I have same problem here with "https"
I'm using 'com.squareup.picasso:picasso:2.5.2' and 'com.squareup.okhttp3:okhttp:3.2.0' but

OkHttpClient client = new OkHttpClient();
client.setProtocols(Arrays.asList(Protocol.HTTP_11));
Picasso picasso = new Picasso.Builder(context)
.downloader(new OkDownloader(client))
.build();

not working @JackDanger @JakeWharton

@alikamts with that combination of dependencies you probably need something more like

final OkHttpClient client = new OkHttpClient.Builder()
        .protocols(Collections.singletonList(Protocol.HTTP_1_1))
        .build();

final Picasso picasso = new Picasso.Builder(this)
        .downloader(new OkHttp3Downloader(client))
        .build();

Picasso.setSingletonInstance(picasso);

where the OkHttp3Downloader instance is supplied by this library.

If this helps anyone else that ran into this: Make sure you have the correct TLS policy if using OkHttp as the download client.

@hscissors I've just been hit by this problem. How to do what you propose?

use SafeOkHttpClient?

I can't load image in https but I haven't any errors.

What can I do?

Hey guys I have made CustomPicasso gist which supports image URL redirection using @JakeWharton's picasso2-okhttp3-downloader

CustomPicasso gist - https://gist.github.com/hrishikesh-kadam/09cef31c736de088313f1a102f5ed3a3

Usage -

CustomPicasso.with(context)
    .load("http://i.imgur.com/DvpvklR.png")
    .into(imageView);

this day in 2018 your solution is still a lifesaver @JakeWharton thx!

is there any solution for self signed certificate ??

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfk4080 picture jfk4080  Â·  19Comments

pfives picture pfives  Â·  17Comments

needz picture needz  Â·  16Comments

sriramr98 picture sriramr98  Â·  21Comments

christopherperry picture christopherperry  Â·  17Comments