How do I remove the Exception Error in running flutter? - flutter

fetchData()async{
res = await http.get(api);
Exception has occurred.
HandshakeException (HandshakeException: Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: self signed certificate in certificate chain(handshake.cc:352)))
print(res.body);
drinks = jsonDecode(res.body)["drinks"];
setState(() {
});

Your error log clearly states that the error is not from flutter app side for api implementation.
Error is from web api side.
Contact your api person to resolve the server side issue.
Also try adding the internet permission in your manifest file,
<uses-permission android:name="android.permission.INTERNET" />
Then, in your terminal run the following command,
flutter clean
If it doesn't work i don't think any issues are from flutte side.

Related

Dio Package doesnot work on Flutter Desktop App

Dio is working perfectly well on both Android and iOS but when I try to run thesame code base on mac Desktop, the application launches but I cant make any http call, I cant connect to any server. It just keeps timing out. I dont know maybe DIO is not compatuble with desktop yet.
This is the error I get
DioError [DioErrorType.other]: SocketException: Connection failed
(OS Error: Operation not permitted, errno = 1),
address = api.wykinkin.app, port = 443
I later discovered I needed to add:
<key>com.apple.security.network.client</key>
<true/>
to my macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements.
from here

SocketException: Failed host lookup: 'methods.abc.com' (OS Error: No address associated with hostname, errno = 7), StackTrace :

I store the API error logs in my DB. I found so many errors on my DB. the log message is the same.
SocketException: Failed host lookup: 'xxx.abc.com' (OS Error: No address associated with hostname, errno = 7), StackTrace :
BTW, This error only occurs to random users. Not for all users.
function
Future<dynamic> abc() async {
var responseJson;
try {
final response = await http.post('${env.url}/xxx/xxx/xxx', headers: {'Authorization': 'Bearer xxx'});
responseJson = _response(response, _errorMap);
return responseJson;
}
catch (e, s) {
errorLog.store('$e, StackTrace : $s', _errorMap);
throw FetchDataException('message');
}
}
env.url looks like this, https://xxx.abc.com
xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="xxx">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application ...
package
http: ^0.12.2
This may not be a Flutter problem. Instead, that is OS Error which is far more low level.
Firstly, have a check at this: Unable to resolve host "<url here>"; No address associated with hostname.
For example, if your user closed his Wifi and mobile network, then you will see this error.
Usually it is not caused by a bug in your code, but just because the user has no network - if he has no network, how can he resolve the domain name!
Thus, for me, personally, I just ignore such type of error. In other words, I do not report these errors to my backend.
Make Sure that you have active internet connection along with permission defined in AndroidManifest.xml
In my case, I restarted my laptop and it was fine. Most of the times restarting computer will solve the problems like this.
First thing we should have a active internet connection.
Second thing we should enable the wifi in our android emulator.
Next thing we should add permissions correctly in AndroidManifest.xml
[Flutter Networking]
: https://docs.flutter.dev/development/data-and-backend/networking
<manifest xmlns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<application ...
</manifest>
Then after we do those steps we should restart the emulator and run the app.
In My case I opened the emulator and after that I connected to the WIFI. So, wifi connected to my system but unable to connect to emulator .
Solutions:
I Closed the emulator and re-open it. And Finally works..

Flutter - How to get api response from a certification errored link

I'm trying to get an api from www.mocky.io, the issue is, when the app starts I'm getting an error like
E/flutter ( 846): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error:
E/flutter ( 846): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))
this is how I'm getting the response.
Future _fetchPost() async {
http.Response response = await http.get(url);
print(response.body);
setState(() {
var convertDatatoJson = json.decode(response.body);
debugPrint(convertDatatoJson.toString());
_data = convertDatatoJson['table_menu_list'];
});}
How can I verify the certificate for this api link for GET method?
I referred this issue, for POST method https://stackoverflow.com/a/54359013/11893608,
any other suggestions would be helpful
Change https to http
it will Resolve your Issue
Use this : http://www.mocky.io/v2/5dfccffc310000efc8d2c1ad
Try adding both http and www.
Example:
http://www.mocky.io/v2/5185415ba171ea3a00704eed
mocky.io may be using www to differentiate between subdomains. That is why its not worked when adding http only.

EPROTO error on google action verification

I am working on an action on google using Actions SDK, however when i enabled the Actions; verification as described at:
https://developers.google.com/actions/reference/rest/verify-requests
I am getting the below error, this only comes when i am behind corporate proxy, can anyone suggest a solution for this?
{
"error": "ID token verification failed: Error: Failed to retrieve verification certificates: Error: write EPROTO 139904972138304:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:825:\n\n at OAuth2Client. (/opt/app/node_modules/actions-on-google/node_modules/google-auth-library/build/src/auth/oauth2client.js:580:31)\n at step (/opt/app/node_modules/actions-on-google/node_modules/google-auth-library/build/src/auth/oauth2client.js:57:23)\n at Object.throw (/opt/app/node_modules/actions-on-google/node_modules/google-auth-library/build/src/auth/oauth2client.js:38:53)\n at rejected (/opt/app/node_modules/actions-on-google/node_modules/google-auth-library/build/src/auth/oauth2client.js:30:65)\n at propagateAslWrapper (/opt/.npm-global/lib/node_modules/ca-apm-probe/node_modules/async-listener/index.js:502:23)\n at /opt/.npm-global/lib/node_modules/ca-apm-probe/node_modules/async-listener/glue.js:188:31\n at /opt/.npm-global/lib/node_modules/ca-apm-probe/node_modules/async-listener/index.js:539:70\n at /opt/.npm-global/lib/node_modules/ca-apm-probe/node_modules/async-listener/glue.js:188:31\n at :null:null\n"
}
I am using v2.5.0 of actions-on-google
So i was able to sort this issue, the underlying issue is with axios library being used by google auth library (v1.3.2)
here is the issue : https://github.com/axios/axios/issues/662
The workaround for me was to replace axios with request promise in google auth library and then publish it in our private npm registry, this solved the issue for now.

Cors request Rejected

I am facing an error and I don't known what to do. Whenever I try to save user to my ionic user service using the following code:
Ionic.io();
var user = Ionic.User.current();
if (user.id) {
user.set('name', username);
//user.set('image',image_name);
}
user.save();
and then I get this error:
Ionic User: Error: CORS request rejected
XMLHttpRequest cannot load https://api.ionic.io/auth/users/null.
Response for preflight has invalid HTTP status code 404
OPTIONS https:// api .ionic .io /auth /users /null
[cors request rejected][1]
[coding][2]
Ionic has a cordova plugin that sorts out all CORS issues called "cordova-plugin-whitelist". When you test through the browser, the Cordova plugins are not active, hence it's not sorting out your issues. Only when you deploy your app to android/ios/windows will the Cordova plugins work.
Rather get "Allow-Control-Allow-Origin" chrome plugin to allow you to make requests if you want to test on your browser.