yami
yami

Reputation: 63

com.bumptech.glide.load.HttpException: Forbidden

I want to use glide to load a url picture

GlideApp.with(this).load("https://files.yande.re/image/0f1c68aa6d34fb3a7a7af855e0036377/yande.re%20404988%20arsenixc%20landscape.jpg").error(R.mipmap.ic_launcher).into(photoView);

but it catch error:

class com.bumptech.glide.load.engine.GlideException: Failed to load resource
08-14 00:59:32.323 15273-15273/com.yaminet.yami I/Glide: Root cause (1 of 1)
                                                     com.bumptech.glide.load.HttpException: Forbidden
                                                         at  com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:118)
                                                         at  com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:53)
                                                         at  com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:95)
                                                         at  com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:144)
                                                         at  com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:138)
                                                         at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59)
                                                         at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:95)
                                                         at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:61)
                                                         at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:282)
                                                         at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:252)
                                                         at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:222)
                                                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                         at java.lang.Thread.run(Thread.java:761)
                                                         at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:347)

How can I load the big picture from the Internet with glide ?

Upvotes: 0

Views: 6811

Answers (1)

jskyzero
jskyzero

Reputation: 46

I also have this error today, because I have used yande's api many times, so, I think maybe this has two possible reason, one is in one time the glide have many request so that the yande serve refuses to responce, the second one is that if you use spider to show yande's picture, you need make your spider like a Internet Expore, use some methods like add headers to http request.

In my code, I add headers, it was solved.

    pictureItem = (PictureItem) getIntent().getExtras().get("PictureItem");
    image = (ImageView) findViewById(R.id.image);

    GlideUrl glideUrl = new GlideUrl(pictureItem.sample_url, new LazyHeaders.Builder()
            .addHeader("User-Agent",
                    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit / 537.36(KHTML, like Gecko) Chrome  47.0.2526.106 Safari / 537.36")
            .build());

    Glide.with(this)
         .load(glideUrl)
         .into(image);

some reference which may help you:

Glide - adding header to request

Yande API

Any way, if we write some code like spider, we should think more about the website we get info from. (smile face)

Upvotes: 3

Related Questions