From 8df52733c26bcdd7a202b58c56eded502e5b198c Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Thu, 17 Oct 2019 09:09:31 +0530 Subject: [PATCH] Update weather.py --- weather.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/weather.py b/weather.py index 36483bd..c78d1da 100644 --- a/weather.py +++ b/weather.py @@ -1,8 +1,21 @@ import requests +import urllib + api_address='http://api.openweathermap.org/data/2.5/weather?appid=0c42f7f6b53b244c78a418f4f181282a&q=' city = input('City Name :') url = api_address + city + +headers = {} +#Header for websites +headers['User-Agent'] = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17" + +#Urllib code +req = urllib.request.Request(url, headers=headers) +resp = urllib.request.urlopen(req) +respData = resp.read() +print(respData) + json_data = requests.get(url).json() format_add = json_data['base'] print(format_add)