Sdwebimage: SdWebImage gives “Error Domain=NSURLErrorDomain Code” A server with the specified hostname could not be found"

Created on 24 Jul 2019  Â·  17Comments  Â·  Source: SDWebImage/SDWebImage

Generating an image call using:

[cell.i_imageView sd_setImageWithURL:[NSURL URLWithString: item.PostimageUrl] placeholderImage:[UIImage imageNamed:@""] options: SDWebImageRefreshCached progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {

   if(!image)
       NSLog(@"image not loaded %@", error.description);

In most cases the image loads fine, but in some cases sdwebimage gives this error code=-1003 "A server with the specified hostname could not be found".

After much research I have found out it's a DNS-related issue and have tested this theory out by using the following methods,

VPN on an actual device
Disconnect the WIFI and use 3G/LTE
To which the images loaded fine. but I can't be betting on both these above mentioned methods while shipping the product, so any workaround or any SdWebImage methods am I missing here that solves the problem.

All 17 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

Still waiting on an answer to this

I think this is not related to SDWebImage, it's related to URLSession behavior. This error code is NSURLErrorDomain domain and code. Maybe Apple forum is a place to find the answer.

Any demo or reproducable way to trigger this error ? Such as DNS config, VPN config, Slow network ? And is there something we can do (Such as something inside NSURLSessionConfiguration) for this ?

The imageURL from fetched from the built-in parser, which are mostly news websites

Is there a way to change DNS, VPN config using sdWebimage when it fails to retrieve the image?

Any demo or reproducable way to trigger this error ? Such as DNS config, VPN config, Slow network ? And is there something we can do (Such as something inside NSURLSessionConfiguration) for this ?

These are all simple websites, but I did notice when you copy the error giving imageURL and open it in browser, it gives "server not found" error, use a vpn it opens

Sample URL that fails:
https://img.thedailybeast.com/image/upload/c_crop,d_placeholder_euli9k,h_2700,w_4800,x_625,y_102/dpr_2.0/c_limit,w_740/fl_lossy,q_auto/v1561973878/RTS2K8SL_bmhdnn

@bpoplauschi @rs @zhongwuzw @matej @kinarobin @akhenakh @mythodeia @robertmryan @mattjgalloway

Maybe you guys can look into this method

- (id <SDWebImageOperation>)loadImageWithURL:(nullable NSURL *)url
                                     options:(SDWebImageOptions)options
                                    progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
                                   completed:(nullable SDInternalCompletionBlock)completedBlock

This seems to go away through this https://github.com/AFNetworking/AFNetworking/issues/967#issuecomment-169718335

Any help in this matter would be highly appreciated, guys?

Have you tried loading the image with a simple NSURLSession call, repeatedly, and see if you get the same errors?

I don’t really see how this can be an SDWebImage related problem.

I have retried calling NSURLSession various times, but it the error persists, However it does go away upon using cellular data.

Maybe it has something to do with method call, and how SDWebimage handles the call?
[cell.i_imageView sd_setImageWithURL:[NSURL URLWithString: item.PostimageUrl] placeholderImage:[UIImage imageNamed:@""] options: SDWebImageRefreshCached progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL)

I have retried calling NSURLSession various times

Do you mean you have tried downloading the image using purely NSURLSession calls, and it's still erroring?

Yes I have put it under sdWebimage completion block as follow,

 if(image == nil)

        {

            NSURLSessionDownloadTask *downloadPhotoTask = [[NSURLSession sharedSession]
                                                           downloadTaskWithURL:[NSURL URLWithString: item.PostimageUrl] completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {

                                                               UIImage *downloadedImage = [UIImage imageWithData:
                                                                                           [NSData dataWithContentsOfURL:location]];
                                                               if(downloadedImage){
                                                                   NSLog(@"i have it");
                                                                   dispatch_async(dispatch_get_main_queue(), ^{
                                                                       cell.i_imageView.image = downloadedImage;
                                                                   });

                                                               }
                                                               else{
                                                                   NSLog(@"i don't have it");
                                                               }
                                                               if (error){
                                                                   NSLog(@"Take care of this guy: %@",error.localizedDescription);
                                                               }
                                                           }];
            [downloadPhotoTask resume];
        }

Gives out the same "A server with the specified hostname could not be found" error, any ideas why?

If you have problems when downloading it with NSURLSession alone, then it's not an SDWebImage problem. You must have something screwy with your internet connection. It's going to be impossible for us to help you here unfortunately.

VPN on an actual device
Disconnect the WIFI and use 3G/LTE

Why does these techniques work out then?

That’s precisely why I’m saying it’s not an SDWebImage issue. It’s your internet. If other connections work then it’s the one that doesn’t work which, well, doesn’t work.

Turns out it was an issue of using cooperate wifi ISP which had these reservations with some URLs that were been test, thanks for correctly pointing this out @mattjgalloway

Cheers to you mate, I'm closing this issue as it was never related to SDWebimage.

Was this page helpful?
0 / 5 - 0 ratings