Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request error, please check your internet connection #11

Open
imacro1212 opened this issue Apr 23, 2024 · 5 comments
Open

request error, please check your internet connection #11

imacro1212 opened this issue Apr 23, 2024 · 5 comments

Comments

@imacro1212
Copy link

Thanks, but the app shows request error, please check your internet connection page. I added my working api key and checked internet permission and the problem still exist. Thanks again.

@ArizArmeidi
Copy link
Owner

are there any errors in the debug log?

@gwabstech
Copy link

same issue no log related

@vnl
Copy link

vnl commented Jul 18, 2024

Same error:
If it helps these are the console logs:

I/flutter ( 4481): Fetched Weather for: Mountain View/US
I/flutter ( 4481): NoSuchMethodError: The method '[]' was called on null.
I/flutter ( 4481): Receiver: null
I/flutter ( 4481): Tried calling: [](0)

@vnl
Copy link

vnl commented Jul 18, 2024

Ah.. I think I figured this out.
The OneCall API needs a different API key, which needs billing enabled.

Uri dailyUrl = Uri.parse(
      'https://api.openweathermap.org/data/2.5/onecall?lat=${location.latitude}&lon=${location.longitude}&units=metric&exclude=minutely,current&appid=$apiKey',
    );

A minor change to add API checks would sort this out.
Some quick bad coding.. but here it is:

       ...      
      final response = await http.get(dailyUrl);
      if (response.statusCode == 401) {
        print('Authentication error: 401 Unauthorized');
        isLoading = false;
        isRequestError = true;
        return;
      }
      final dailyData = json.decode(response.body) as Map<String, dynamic>;
      ....

OR

Just subscribe to OneCall 3.0: https://openweathermap.org/api/one-call-3 and give it some time to register and then change the URL to something like this:

Uri dailyUrl = Uri.parse(
      'https://api.openweathermap.org/data/3.0/onecall?lat=${location.latitude}&lon=${location.longitude}&units=metric&exclude=minutely,current&appid=$apiKey',
    );

@ArizArmeidi
Copy link
Owner

Ah.. I think I figured this out. The OneCall API needs a different API key, which needs billing enabled.

Uri dailyUrl = Uri.parse(
      'https://api.openweathermap.org/data/2.5/onecall?lat=${location.latitude}&lon=${location.longitude}&units=metric&exclude=minutely,current&appid=$apiKey',
    );

A minor change to add API checks would sort this out. Some quick bad coding.. but here it is:

       ...      
      final response = await http.get(dailyUrl);
      if (response.statusCode == 401) {
        print('Authentication error: 401 Unauthorized');
        isLoading = false;
        isRequestError = true;
        return;
      }
      final dailyData = json.decode(response.body) as Map<String, dynamic>;
      ....

OR

Just subscribe to OneCall 3.0: https://openweathermap.org/api/one-call-3 and give it some time to register and then change the URL to something like this:

Uri dailyUrl = Uri.parse(
      'https://api.openweathermap.org/data/3.0/onecall?lat=${location.latitude}&lon=${location.longitude}&units=metric&exclude=minutely,current&appid=$apiKey',
    );

Hmmm that's weird, my billing is turned off and I'm using the OneCall version 2.5 as stated in the readme. I will double check again it could be a regional thing. in the meantime when I have the time I will try to update the code to handle it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants