Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Request Errors
#7
(Jan-07-2021, 03:17 PM)ndc85430 Wrote: Why the rubbish variable names x, y and z instead of more meaningful ones like you have for other things?

like this

import requests, json 
 
api_key = "2eacaa2c66e011c77935d17f0b7a72ed"
base_url = "http://api.openweathermap.org/data/2.5/weather?"
city_name = "Berlin" ###input("Enter city name : ") 
complete_url = base_url + "appid=" + api_key + "&q=" + city_name 
 
response = requests.get(complete_url) 

x = response.json() 

if x["cod"] != "404": 

    y = x["main"] 
    current_temperature = f'{(float(y["temp"]) - 273.15):.1f}°C'
    current_pressure = f'{y["pressure"]} hPa'
    current_humidiy = f'{y["humidity"]}%'
    z = x["weather"] 
    weather_description = z[0]["description"] 
 
    print(f'Weather in {city_name}:\n\
Temperature: {current_temperature}\n\
atmospheric: {current_pressure}\n\
humidity: {current_humidiy}\n\
description: {weather_description}')
 
else: 
    print(" City Not Found ")
Output:
Weather in Berlin: Temperature: 1.8°C atmospheric: 1010 hPa humidity: 80% description: light snow
Reply


Messages In This Thread
Python Request Errors - by PythonNoob1998 - Jan-07-2021, 02:43 PM
RE: Python Request Errors - by Axel_Erfurt - Jan-07-2021, 02:43 PM
RE: Python Request Errors - by PythonNoob1998 - Jan-07-2021, 02:47 PM
RE: Python Request Errors - by buran - Jan-07-2021, 02:59 PM
RE: Python Request Errors - by PythonNoob1998 - Jan-07-2021, 03:12 PM
RE: Python Request Errors - by ndc85430 - Jan-07-2021, 03:17 PM
RE: Python Request Errors - by Axel_Erfurt - Jan-07-2021, 04:41 PM
RE: Python Request Errors - by buran - Jan-07-2021, 05:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  When does Python detect Errors? stamp1t 1 483 Oct-21-2023, 05:53 PM
Last Post: deanhystad
  how can I correct the Bad Request error on my curl request tomtom 8 5,153 Oct-03-2021, 06:32 AM
Last Post: tomtom
  Rmarkdown opened by python code - errors Rav013 0 2,129 Apr-27-2021, 03:13 PM
Last Post: Rav013
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 3,983 Jun-18-2020, 08:07 AM
Last Post: buran
  Pip Syntax Errors in CMD: Windows 10 and Python 3.8.1 jamesphopper 2 4,521 Feb-08-2020, 07:21 PM
Last Post: jamesphopper
  Python stops without errors shahgourav 4 2,823 Feb-04-2020, 11:44 PM
Last Post: micseydel
  Can the comments produce errors in python? newbieAuggie2019 9 4,409 Nov-26-2019, 12:19 AM
Last Post: micseydel
  Running into errors when installing pip and pip3 on python 2.7 and python 3.6 tej7gandhi 1 2,886 May-05-2019, 10:37 PM
Last Post: snippsat
  Does Python sqlite3 detect connection errors zatlas1 6 4,079 Jan-18-2019, 06:02 AM
Last Post: zatlas1
  Errors in Python dttomoum 1 2,740 May-23-2018, 08:57 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020