dart-lang / http

A composable API for making HTTP requests in Dart.
https://pub.dev/packages/http
BSD 3-Clause "New" or "Revised" License
1.03k stars 358 forks source link

No address associated with hostname #185

Closed techyrajeev closed 6 years ago

techyrajeev commented 6 years ago

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);
});

}

ghost commented 6 years ago

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

GurgenHOVH commented 5 years ago

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

aidooyaw1992 commented 5 years ago

thank you, this worked for me

NataliaPena commented 5 years ago

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.

Svoka commented 5 years ago

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

natebosch commented 5 years ago

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.

Derkin commented 5 years ago

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

natebosch commented 5 years ago

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

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

balajiks-dev commented 5 years ago

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

Abdusin commented 5 years ago

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

TomOerlemans commented 4 years ago

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

jawale204 commented 4 years ago

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???

natebosch commented 4 years ago

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

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

dsouzajaison commented 4 years ago

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.

gulmensedat commented 4 years ago

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.

1pavanb commented 4 years ago

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! 👍🤝

aloev commented 4 years ago

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!

alokkumax commented 4 years ago

@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

gitayanbhat commented 3 years ago

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....

jaiwaikhom commented 3 years ago

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

gitayanbhat commented 3 years ago

Failed Host Lookup error occurs when their is no internet connection in the AVD in the laptop...... Suggestion is to close the AVD, check your internet connection and then open your AVD and then run again......

Also if their is a problem in the API itself the. This error might occur..........

gitayanbhat commented 3 years ago

That's how I did solve it...

alokkumax commented 3 years ago

Just restart the emulator that's it

On Tue, Dec 15, 2020, 8:15 AM AYAN BHATTACHARYA notifications@github.com wrote:

That's how I did solve it...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dart-lang/http/issues/185#issuecomment-745015911, or unsubscribe https://github.com/notifications/unsubscribe-auth/AODLGO5DP76Y5W2BSK5ROPTSU3EWBANCNFSM4FLL2Q5Q .

abdesselam-benameur commented 3 years ago

I had this issue and the cause of this error for me was that my phone was not connected to the internet 🤦‍♂️

mariokresic commented 3 years ago

I've faced this issue after trying to build my flutter apk for the first time, with the intention to test it on a real android device.

After building, the issue occurred on both devices (real and emulator).

What helped was reinstalling the http package.

JoyEnergiser commented 3 years ago

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

Thanks you are my hero! same issue hehe

Zaid101 commented 3 years ago

my problem was with the api url it was inccorect.

asbansal commented 3 years ago

In my real android device, it is NOT working with Jio internet. With airtel and other networks, it's working fine. Do telecom operators put proxy etc. in the http requests?

gururaja-kambala commented 3 years ago

In my real android device, it is NOT working with Jio internet. With airtel and other networks, it's working fine. Do telecom operators put proxy etc. in the http requests?

For our app users using Jio network this issue happens some times. On same device it works some time, and does not work some time. Server has ipv4-only ip. Only A record is set on DNS server.

asbansal commented 3 years ago

In my real android device, it is NOT working with Jio internet. With airtel and other networks, it's working fine. Do telecom operators put proxy etc. in the http requests?

For our app users using Jio network this issue happens some times. On same device it works some time, and does not work some time. Server has ipv4-only ip. Only A record is set on DNS server.

I solved it by changing api url. Jio uses some SNI url filtering mechanism.

https://cis-india.org/internet-governance/blog/reliance-jio-is-using-sni-inspection-to-block-websites .

So for some reason my previous api endpoint was not being hit.

errorsolve commented 3 years ago

[Solved] How to solve SocketException: Failed host lookup: ‘flutter-project-xxxxx.firebaseio.com’ (OS Error: No address associated with hostname, errno = 7)

Shybeen commented 3 years ago

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

stereo-type commented 2 years ago

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

Yes. I have same problem. When i turn VPN ON i have failed host lookup, but internet is working in browser. My requests is not, how can i fix it? I really need work with VPN

Mohamed-Reda1010 commented 1 year ago

i tried every thing , nothing work !!

deepatavy commented 1 year ago

We receive this error when running our app for a specific internet provider. We tried hitting same API for same network provider by native android app , it worked fine. but with flutter it did not work. App works fine when we use VPN. Without VPN we are receiving this error. anyone can suggest anything.. that would be great help... Thanks

dhruv-kabariya commented 4 months ago

In my real android device, it is NOT working with Jio internet. With airtel and other networks, it's working fine. Do telecom operators put proxy etc. in the http requests?

For our app users using Jio network this issue happens some times. On same device it works some time, and does not work some time. Server has ipv4-only ip. Only A record is set on DNS server.

I solved it by changing api url. Jio uses some SNI url filtering mechanism.

https://cis-india.org/internet-governance/blog/reliance-jio-is-using-sni-inspection-to-block-websites .

So for some reason my previous api endpoint was not being hit.

Can you tell me what exactly you did. Because I am facing same issue

dhruv-kabariya commented 4 months ago

In my real android device, it is NOT working with Jio internet. With airtel and other networks, it's working fine. Do telecom operators put proxy etc. in the http requests?

For our app users using Jio network this issue happens some times. On same device it works some time, and does not work some time. Server has ipv4-only ip. Only A record is set on DNS server.

What is solution then ?