Unable to fetch an icon from the URL
from tkinter import *
from PIL import ImageTk, Image
import requests
from io import BytesIO
root = Tk()
root.geometry("250x400")
root.title("Weather Report")
root.configure(bg="#50514F")
def weather(root):
try:
cityName = inputCity.get()
#getting info from the API
jsonData = requests.get(
'http://api.openweathermap.org/data/2.5/weather?q=' + cityName + ` here`'&appid=ddb74ff40d******81caef7e945640e02').json()
condition = jsonData['weather'][0]['main']
temp = int(jsonData['main']['temp']) - 273.15
desc = jsonData['weather'][0]['description']
icon = jsonData['weather'][0]['icon']
temp_min = int(jsonData['main']['temp_min']) - 273.15
temp_max = int(jsonData['main']['temp_max']) - 273.15
pressure = jsonData['main']['pressure']
setDesc = condition + str(int(temp)) + "°C" + "\n" + desc + "\n"
setInfo = str(int(temp_min)) + "°C" + " Min" + "\n" + str(int(temp_max)) + "°C" + " Max" + "\n" str(pressure) + "Pa"
icon_Id = jsonData['weather'][0]['icon']
icon1 = requests.get(f'http://openweathermap.org/img/wn/{icon}.png'.format(icon=icon_Id))
icon_Data = icon1.content
icon_detail = ImageTk.PhotoImage(Image.open(BytesIO(icon_Data)))
# setting icons
label1.config(text=setDesc)
label2.config(text=setInfo)
label3.config(image=icon_detail)
except:
label1.config(text="Error !! wrong City Name!")
label2.config(text="")
label3.config(text=" ")
# tkinter intry box and label creation
inputCity = Entry(root, width='15', justify='center', font=('Roboto', 15))
inputCity.focus()
inputCity.bind('<Return>', weather)
inputCity.pack(pady="11")
label1 = Label(font=("Raleway-MediumItalic", 15), background="#50514F", foreground="#F6E8EA")
label1.pack(pady="10")
label2 = Label(font=("Raleway-MediumItalic", 15), background="#50514F", foreground="#F6E8EA")
label2.pack(pady="10")
label3 = Label(background="#50514F")
label3.pack(pady="10")
mainloop()
I am trying to display the weather icon but unfortunately, it is not working. Please figure me out #where I am going wrong.
I am using open weather API for fetching icons and weather information.
I want to show the weather icon on the middle of the details.