diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2023-05-04 16:34:47 -0700 |
|---|---|---|
| committer | Pinapelz <donaldshan1@outlook.com> | 2023-05-04 16:34:47 -0700 |
| commit | 2878c453ec7d7b5874fc9734dbf423963dd9ca2f (patch) | |
| tree | 993cea5fa5d2bc33708f63c57e49a45cdcb5abaa | |
| parent | 95f604cc62a96b31e2ac0797e447e09b9158efb3 (diff) | |
Added option to specify header name for different apis
| -rw-r--r-- | webapi/web_api.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/webapi/web_api.py b/webapi/web_api.py index 1b16681..525994c 100644 --- a/webapi/web_api.py +++ b/webapi/web_api.py @@ -11,7 +11,7 @@ class WebAPI: self.api_key = api_key self.base_url = base_url - def _download_url(self, query: str) -> dict: + def _download_url(self, query: str, header = 'X-APIKEY') -> dict: """ Downloads the URL and returns the result as a string param: @@ -20,7 +20,7 @@ class WebAPI: if self.api_key is None: raise Exception("API key not set") opener = urllib.request.build_opener() - opener.addheaders = [('X-APIKEY', self.api_key)] + opener.addheaders = [(header, self.api_key)] urllib.request.install_opener(opener) response = urllib.request.urlopen(self.base_url + query) json_results = response.read() |
