http icon indicating copy to clipboard operation
http copied to clipboard

No address associated with hostname

Open techyrajeev opened this issue 8 years ago • 38 comments

Getting this error while calling api.

Sometimes I receive response occasionally. I tested the api using postman it is working perfectly fine. Version: http: ^0.11.3+16 [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception: E/flutter (24807): SocketException: Failed host lookup: 'api.xyz.com' (OS Error: No address associated with hostname, errno = 7) E/flutter (24807): #0 IOClient.send (package:http/src/io_client.dart:30:23) E/flutter (24807): <asynchronous suspension> E/flutter (24807): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:171:38) E/flutter (24807): <asynchronous suspension> E/flutter (24807): #2 BaseClient.post (package:http/src/base_client.dart:56:5) E/flutter (24807): #3 post.<anonymous closure> (package:http/http.dart:70:34) E/flutter (24807): #4 _withClient (package:http/http.dart:167:20) E/flutter (24807): <asynchronous suspension> E/flutter (24807): #5 post (package:http/http.dart:70:3) E/flutter (24807): #6 NetworkUtil.post (package:ddictor/utils/network_util.dart:29:10) E/flutter (24807): #7 loginUser (package:ddictor/utils/api.dart:23:16)

post method inside network_util file

` Future post(String url, {Map headers, body, encoding}) { return http .post(url, body: body, headers, encoding: encoding) .then((http.Response response) { final String res = response.body; final int statusCode = response.statusCode;

  if (statusCode < 200 || statusCode > 400 || json == null) {
    throw new Exception("Error while fetching data");
  }
  return _decoder.convert(res);
});

}

techyrajeev avatar Jul 23 '18 13:07 techyrajeev

The errors Failed host lookup: 'api.xyz.com' and OS Error: No address associated with hostname usually mean that your DNS lookup fails. As hinted by OS Error this is usually a system-level error and nothing specific to http or Dart.

To diagnose this on your system you can try check e.g. your browser can DNS resolve the host in question. And/or if you're on a Mac/Linux system you might be able to run dig api.xyz.com to see if that resolves.

When doing anything network, or I/O in general, it's a good idea to program very defensively and assume the I/O can sporadically fail or time out. You can try see if you can make your code degrade more gracefully in cases when e.g. DNS isn't working as expected.

I'll go ahead and close this issue since I don't think there's anything to be done in http

ghost avatar Aug 23 '18 12:08 ghost

Anyone facing this issue: try adding <uses-permission android:name="android.permission.INTERNET" /> to your AndroidManifest.xml.

GurgenHOVH avatar Mar 01 '19 20:03 GurgenHOVH

thank you, this worked for me

aidooyaw1992 avatar Mar 20 '19 17:03 aidooyaw1992

I had the same error. In my case it was because the emulator of the phone that I am using does not have access to the internet.

Run the application on a physical mobile device and it worked immediately.

Solution connect the emulator to the internet.

NataliaPena avatar May 28 '19 19:05 NataliaPena

I think we need to add message that you need to add internet permission in Install section of doc

Svoka avatar Jun 07 '19 13:06 Svoka

I think we need to add message that you need to add internet permission in Install section of doc

Please +1 and follow https://github.com/flutter/flutter/issues/29688

If we have some flutter docs to point to from this README we can do that.

natebosch avatar Jun 07 '19 19:06 natebosch

I have the same issue when run in release mode,but it is ok when debug mode !

Derkin avatar Sep 04 '19 09:09 Derkin

@Derkin - please raise the issue at flutter/flutter#29688

This isn't a problem that can be solved in this package.

natebosch avatar Sep 04 '19 17:09 natebosch

Hi, This error is because if your Simulator or Your phone doesn't connect to the Internet.

balajiks-dev avatar Sep 25 '19 08:09 balajiks-dev

Anyone facing this issue: try adding <uses-permission android:name="android.permission.INTERNET" /> to your AndroidManifest.xml.

@gurgenDP pls help me this way dont solve my problem flutter/flutter/#43357

Abdusin avatar Oct 23 '19 17:10 Abdusin

Just ran into this issue. After about half an hour I finally figured out that it was because I had my VPN on..

TomOerlemans avatar Nov 26 '19 16:11 TomOerlemans

I have the same issue when run in release mode,but it is ok when debug mode !

i have same issue with my app . So have u figured it out now???

jawale204 avatar Dec 11 '19 07:12 jawale204

@jawale204 - please raise the issue at flutter/flutter#29688

This isn't a problem that can be solved in this package.

natebosch avatar Dec 11 '19 23:12 natebosch

I have the same issue when run in release mode,but it is ok when debug mode !

i have same issue with my app . So have u figured it out now???

This error is because if your Simulator or Your phone doesn't connect to the Internet.

dsouzajaison avatar Mar 03 '20 23:03 dsouzajaison

I made new minor sdk updates, upgraded the http package, closed the emulator and re-opened it, and stopped the application and re-compiled the problem was fixed.

gulmensedat avatar Aug 03 '20 08:08 gulmensedat

The errors Failed host lookup: 'api.xyz.com' and OS Error: No address associated with hostname usually mean that your DNS lookup fails. As hinted by OS Error this is usually a system-level error and nothing specific to http or Dart.

To diagnose this on your system you can try check e.g. your browser can DNS resolve the host in question. And/or if you're on a Mac/Linux system you might be able to run dig api.xyz.com to see if that resolves.

When doing anything network, or I/O in general, it's a good idea to program very defensively and assume the I/O can sporadically fail or time out. You can try see if you can make your code degrade more gracefully in cases when e.g. DNS isn't working as expected.

I'll go ahead and close this issue since I don't think there's anything to be done in http

that was valuable insight, thanks @cskau-g man. I was worried about this issue. It was DNS, I was messing with my DNS settings.

people kept spamming about the missing Internet Permission. That wasn't my case. It was hard to find this info. I'll set the DNS to default settings and see if it's resolved.

thanks again! 👍🤝

1pavanb avatar Aug 08 '20 16:08 1pavanb

I had the same error. In my case it was because the emulator of the phone that I am using does not have access to the internet.

Run the application on a physical mobile device and it worked immediately.

Solution connect the emulator to the internet.

This solved the issue for me. Thanks a lot!

aloev avatar Sep 03 '20 18:09 aloev

@jawale204 - please raise the issue at flutter/flutter#29688

This isn't a problem that can be solved in this package.

step 1 add to you androidmanifest, if done, step 2 connect your emulator to a internet, if you cant use in on your physical device

alokkumax avatar Nov 01 '20 09:11 alokkumax

Anyone facing this issue: try adding <uses-permission android:name="android.permission.INTERNET" /> to your AndroidManifest.xml.

HAVE TRIED THE ABOVE BUT THE SAME ERROR EXISTS PLS HELP....

gitayanbhat avatar Nov 19 '20 12:11 gitayanbhat

I am also facing the same error after doing all the steps mentioned above. Please suggest.

jaiwaikhom avatar Dec 15 '20 02:12 jaiwaikhom