Last active
January 27, 2021 04:10
-
-
Save hellodit/c62581675a9224dba11fb9ace8e1422f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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