0

I have a mini project about "Weather App", i use Nominatim to get location but it seems like not working.

Here is the code

from tkinter import *
import tkinter as tk
from geopy.geocoders import Nominatim
from tkinter import ttk,messagebox
from timezonefinder import TimezoneFinder
from datetime import *
import requests
import pytz
from PIL import Image, ImageTk

root = Tk() root.title("Weather App") root.geometry("900x500+300+200") root.configure(bg = "#57adff") root.resizable(False, False)

#get weather

def getWeather(): city = textfield.get() geolocator = Nominatim(user_agent = "geoapiExercises") location= geolocator.geocode(city, timeout = None) obj = TimezoneFinder()

result = obj.timezone_at(lng = location.longitude, lat = location.latitude)

timezone.config(text=result)
long_lat.config(text = f"{round(location.latitude,4)}°N, {round(location.longitude,4)}°E")

home = pytz.timezone(result)
local_time = datetime.now(home)
current_time = local_time.strftime("%I:%M %p")
clock.config(text = current_time)

and the problem

        Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\84985\AppData\Local\Programs\Python\Python311\Lib\site-packages\geopy\geocoders\base.py", line 368, in _call_geocoder
    result = self.adapter.get_json(url, timeout=timeout, headers=req_headers)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\84985\AppData\Local\Programs\Python\Python311\Lib\site-packages\geopy\adapters.py", line 472, in get_json
    resp = self._request(url, timeout=timeout, headers=headers)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\84985\AppData\Local\Programs\Python\Python311\Lib\site-packages\geopy\adapters.py", line 500, in _request
    raise AdapterHTTPError(
geopy.adapters.AdapterHTTPError: Non-successful status code 403

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\84985\AppData\Local\Programs\Python\Python311\Lib\tkinter__init__.py", line 1948, in call return self.func(*args) ^^^^^^^^^^^^^^^^ File "v:\PYTHON\Python Weather Project\weather.py", line 24, in getWeather location= geolocator.geocode(city, timeout = None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\84985\AppData\Local\Programs\Python\Python311\Lib\site-packages\geopy\geocoders\nominatim.py", line 297, in geocode return self._call_geocoder(url, callback, timeout=timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\84985\AppData\Local\Programs\Python\Python311\Lib\site-packages\geopy\geocoders\base.py", line 388, in _call_geocoder res = self._adapter_error_handler(error) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\84985\AppData\Local\Programs\Python\Python311\Lib\site-packages\geopy\geocoders\base.py", line 411, in _adapter_error_handler raise exc_cls(str(error)) from error geopy.exc.GeocoderInsufficientPrivileges: Non-successful status code 403

til_b
  • 5,074
  • 1
  • 19
  • 36
Ban Mike
  • 3
  • 2

1 Answers1

1

You use: geolocator = Nominatim(user_agent = "geoapiExercises")

Replace with this: geolocator = Nominatim(user_agent = "abcd")

Vincé
  • 1,416
  • 4
  • 17
anton asd
  • 26
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Community Oct 27 '23 at 02:56