Skip to content

Instantly share code, notes, and snippets.

@hellodit
Last active January 27, 2021 04:10
Show Gist options
  • Save hellodit/c62581675a9224dba11fb9ace8e1422f to your computer and use it in GitHub Desktop.
Save hellodit/c62581675a9224dba11fb9ace8e1422f to your computer and use it in GitHub Desktop.
def get_weather_info(location):
try:
response = requests.get("http://api.weatherstack.com/current?access_key=ebd06089ca30cb46428616818d96d6ca&query="+location)
# If the response was successful, no Exception will be raised
result = response.json()
if 'success' in result and result['success'] == False:
raise TypeError("`Location not valid")
return result
except HTTPError as http_err:
return print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
return print(f'Other error occurred: {err}') # Python 3.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment