Unhandled Exception: SocketException: Failed host lookup: (OS Error: No address associated with hostname, errno = 7)

7,363

The error SocketException: Failed host lookup: 'api.xyz.com' (OS Error: No address associated with hostname, errno = 7) usually means that your DNS lookup fails. From the error itself OS Error, is usually a system-level error and nothing specific to http or Dart/Flutter.

You might need to adjust some settings in your DNS. Also, if you are using a Mac/Linux system you might be able to run dig api.xyz.com to see if that resolves.

Running your app in the actual device could be possible as well since there is a possibility its getting an error in your virtual device due to DNS settings or the virtual device you are using is not connected to the internet. You will be able to isolate the problem.

Share:
7,363
Nyuu
Author by

Nyuu

Updated on December 17, 2022

Comments

  • Nyuu
    Nyuu over 1 year

    we already have a release version in playstore and its working just fine. But suddenly now when we try to build and run the code again since we want to add new functionality. It would no longer communicate with our backend.

    So i searched the net using the error as keyword and saw that need INTERNET PERMISSION as the 100% result and answer, which we have already and not helpful at all. Yes we have it in debug and live manifests.

    The server is up we can access it in the browser and as well as postman also dig command Using DIG

    So i searched more things in the net to no avail, found about the because proxy issue thing i tried both client side and server-side. we don't have proxy

    Client Side

    Server Side

    we use simple request only like this:

     static Future getDriver(String phone){
       var url = baseUrl + "/mobile/driverPhone";
       return http.post(url,body: {
         "phone" : phone
       });
     }
    

    also some suggestion say to use DIO, but i want to know the reason first before i gave up with this http plugin. Can someone with good heart explain and help me with this?

    P.S. we on master channel, here are some error logs enter image description here

    • MNFS
      MNFS over 3 years
      any update for your issue?
    • Nyuu
      Nyuu over 3 years
      bro this question was like months ago, sorry, I moved to DIO, and it's all good now, not sure about it anymore today
  • Nyuu
    Nyuu over 3 years
    I changed the HTTP plugin and its no longer an issue, also I did use dig look at the pictures I provided, running the app on a phone via creating a new apk also did not work, you see it is a plugin issue cuz our old build is fine and working, my guess is that conflicts with other new plugins or something which is illogical to you right? but when I changed the HTTP plugin to DIO shit disappeared and working properly