Skip to content

Commit fb2eeb9

Browse files
committed
use existing Tornado library
1 parent 2f19a0d commit fb2eeb9

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

cylc/uiserver/client.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616

1717
import json
1818
import os
19-
import requests
2019
from shutil import which
2120
import socket
2221
import sys
2322
from typing import Any, Optional, Union, Dict
23+
from tornado.httpclient import (
24+
AsyncHTTPClient,
25+
HTTPRequest,
26+
HTTPClientError
27+
)
2428

2529
from cylc.flow import LOG
26-
from cylc.flow.exceptions import ClientError, ClientTimeout
30+
from cylc.flow.exceptions import ClientError
2731
from cylc.flow.network import encode_
2832
from cylc.flow.network.client import WorkflowRuntimeClientBase
2933
from cylc.flow.network.client_factory import CommsMeth
@@ -43,7 +47,7 @@ def __init__(
4347
port: Union[int, str, None] = None,
4448
timeout: Union[float, str, None] = None,
4549
):
46-
self.timeout = timeout
50+
self.timeout = timeout or self.DEFAULT_TIMEOUT
4751
# gather header info post start
4852
self.header = self.get_header()
4953

@@ -72,36 +76,34 @@ async def async_request(
7276
if req_meta:
7377
msg['meta'].update(req_meta)
7478

75-
LOG.debug('http:send %s', msg)
79+
LOG.debug('https:send %s', msg)
7680

7781
try:
78-
res = requests.post(
79-
api_info["url"] + 'cylc/graphql',
82+
request = HTTPRequest(
83+
url=api_info["url"] + 'cylc/graphql',
84+
method='POST',
8085
headers={
8186
'Authorization': f'token {api_info["token"]}',
87+
'Content-Type': 'application/json',
8288
'meta': encode_(msg.get('meta', {})),
8389
},
84-
json={
85-
'query': args['request_string'],
86-
'variables': args.get('variables', {}),
87-
},
88-
timeout=self.timeout
89-
)
90-
res.raise_for_status()
91-
except requests.ConnectTimeout:
92-
raise ClientTimeout(
93-
'Timeout waiting for server response.'
94-
' This could be due to network or server issues.'
95-
' Check the UI Server log.'
90+
body=json.dumps(
91+
{
92+
'query': args['request_string'],
93+
'variables': args.get('variables', {}),
94+
}
95+
),
96+
request_timeout=float(self.timeout)
9697
)
97-
except requests.ConnectionError as exc:
98+
res = await AsyncHTTPClient().fetch(request)
99+
except HTTPClientError as exc:
98100
raise ClientError(
99-
'Unable to connect to UI Server or Hub.',
101+
'Client error with Hub/UI-Server request.',
100102
f'{exc}'
101103
)
102104

103-
response = res.json()
104-
LOG.debug('http:recv %s', response)
105+
response = json.loads(res.body)
106+
LOG.debug('https:recv %s', response)
105107

106108
try:
107109
return response['data']

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ install_requires =
5757
jupyter_server>=1.10.2
5858
tornado>=6.1.0 # matches jupyter_server value
5959
traitlets>=5.2.1 # required for logging_config (5.2.0 had bugs)
60-
requests==2.28.*
6160

6261
# Transitive dependencies that we directly (lightly) use:
6362
pyzmq

0 commit comments

Comments
 (0)