Skip to content

Commit 9741f11

Browse files
committed
Basically copy/paste from Min's comment.
I also ran through `black`.
1 parent aa37505 commit 9741f11

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

batchspawner/singleuser.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import os
32
import sys
43

@@ -8,7 +7,7 @@
87
from jupyterhub.utils import random_port, url_path_join
98
from jupyterhub.services.auth import HubAuth
109

11-
from tornado.escape import json_encode
10+
import requests
1211

1312

1413
def main(argv=None):
@@ -17,12 +16,22 @@ def main(argv=None):
1716
hub_auth.client_ca = os.environ.get("JUPYTERHUB_SSL_CLIENT_CA", "")
1817
hub_auth.certfile = os.environ.get("JUPYTERHUB_SSL_CERTFILE", "")
1918
hub_auth.keyfile = os.environ.get("JUPYTERHUB_SSL_KEYFILE", "")
20-
asyncio.run(
21-
hub_auth._api_request(
22-
method="POST",
23-
url=url_path_join(hub_auth.api_url, "batchspawner"),
24-
body=json_encode({"port": port}),
25-
)
19+
20+
url = url_path_join(hub_auth.api_url, "batchspawner")
21+
headers = {"Authorization": f"token {hub_auth.api_token}"}
22+
23+
# internal_ssl kwargs
24+
kwargs = {}
25+
if hub_auth.certfile and hub_auth.keyfile:
26+
kwargs["cert"] = (hub_auth.certfile, hub_auth.keyfile)
27+
if hub_auth.client_ca:
28+
kwargs["verify"] = hub_auth.client_ca
29+
30+
r = requests.post(
31+
url,
32+
headers={"Authorization": f"token {hub_auth.api_token}"},
33+
json={"port": port},
34+
**kwargs,
2635
)
2736

2837
cmd_path = which(sys.argv[1])

0 commit comments

Comments
 (0)