|
1 | 1 | import json
|
2 | 2 | import os
|
| 3 | +import platform |
3 | 4 | import sys
|
4 | 5 | from concurrent.futures import ThreadPoolExecutor, as_completed
|
5 | 6 | from datetime import datetime
|
@@ -42,6 +43,8 @@ class Client:
|
42 | 43 |
|
43 | 44 | JQUANTS_API_BASE = "https://api.jpx-jquants.com/v1"
|
44 | 45 | MAX_WORKERS = 5
|
| 46 | + USER_AGENT = "jqapi-python" |
| 47 | + USER_AGENT_VERSION = "0.0.0" |
45 | 48 | RAW_ENCODING = "utf-8"
|
46 | 49 |
|
47 | 50 | def __init__(
|
@@ -165,7 +168,10 @@ def _base_headers(self) -> dict:
|
165 | 168 | J-Quants API にアクセスする際にヘッダーにIDトークンを設定
|
166 | 169 | """
|
167 | 170 | id_token = self.get_id_token()
|
168 |
| - headers = {"Authorization": f"Bearer {id_token}"} |
| 171 | + headers = { |
| 172 | + "Authorization": f"Bearer {id_token}", |
| 173 | + "User-Agent": f"{self.USER_AGENT}/{self.USER_AGENT_VERSION} p/{platform.python_version()}", |
| 174 | + } |
169 | 175 | return headers
|
170 | 176 |
|
171 | 177 | def _request_session(
|
@@ -249,7 +255,13 @@ def _post(
|
249 | 255 | """
|
250 | 256 | s = self._request_session()
|
251 | 257 |
|
252 |
| - ret = s.post(url, data=data, json=json, headers=headers, timeout=30) |
| 258 | + base_headers = { |
| 259 | + "User-Agent": f"{self.USER_AGENT}/{self.USER_AGENT_VERSION} p/{platform.python_version()}", |
| 260 | + } |
| 261 | + if headers is not None: |
| 262 | + base_headers.update(headers) |
| 263 | + |
| 264 | + ret = s.post(url, data=data, json=json, headers=base_headers, timeout=30) |
253 | 265 | ret.raise_for_status()
|
254 | 266 | return ret
|
255 | 267 |
|
|
0 commit comments