Connections
Learn how to connect with third-party tools and services in your custom book project.
Implementing Connections
Multiple Connections
Method Docstrings
1. Arguments
2. Labels
@connect(noun_phrase="api keys")
def connect(self, api_key: str):
"""
Authenticate to Open Weather API using the specified API key. You can obtain your own API key by visiting
Open Weather's website at https://openweathermap.org/appid.
Arguments:
api_key: The API key to be used for connecting
Labels:
api_key: API Key
"""
api_key = os.getenv("API_KEY", api_key)
test_url = f"{self._base_url}?appid={api_key}&q=London"
response = requests.get(test_url, timeout=self._timeout)
if response.status_code == 401:
response_data = response.json()
if "Invalid API key" in response_data.get("message", ""):
raise ValueError("Invalid API key")
self._api_key = api_keyLast updated
Was this helpful?

