Skip to content

Commit c56a105

Browse files
authored
feat: use the app for API requests (#138)
* feat: use the app for api requests Instead of making people forward baseport + 2 * feat: send user agent with tools API requests * fix: correct api suffix use
1 parent f6e0c97 commit c56a105

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cryosparc/constants.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
Bytes in 8 mebibytes
99
"""
1010

11-
# TODO: Correct suffix when app updates
12-
# API_SUFFIX = "/api/cmd_spm"
13-
API_SUFFIX = ""
11+
API_SUFFIX = "/api/cmd"
1412
"""
1513
Path to API for CryoSPARC app URL
1614
"""

cryosparc/tools.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(
162162
if base_url:
163163
raise TypeError("Cannot specify host or base_port when base_url is specified")
164164
host = host or "localhost"
165-
port = int(base_port or 39000) + 2 # TODO: use base_port + 0 when this works
165+
port = int(base_port or 39000)
166166
self.base_url = f"http://{host}:{port}"
167167
elif base_url:
168168
self.base_url = base_url
@@ -186,7 +186,12 @@ def __init__(
186186

187187
tools_major_minor_version = ".".join(__version__.split(".")[:2]) # e.g., 4.1.0 -> 4.1
188188
try:
189-
self.api = APIClient(f"{self.base_url}{API_SUFFIX}", auth=auth, timeout=timeout)
189+
self.api = APIClient(
190+
f"{self.base_url}{API_SUFFIX}",
191+
auth=auth,
192+
headers={"User-Agent": f"cryosparc-tools/{__version__}"},
193+
timeout=timeout,
194+
)
190195
assert self.user # trigger user profile fetch
191196
cs_version = self.api.config.get_version()
192197
except Exception as e:

0 commit comments

Comments
 (0)