fix: Don't raise ex if var isn't defined in req path
This commit is contained in:
1 parent
e42d814c84
commit
dd966967df
2 files changed
+9
-7
No files matched your search
@@ -8,7 +8,6 @@ import time
|
||||
import websocket
|
||||
import json
|
||||
import requests
|
||||
from string import Template
|
||||
from threading import Thread
|
||||
from typing import Any, Callable, Optional, TextIO
|
||||
|
||||
@@ -152,11 +151,10 @@ class BinanceClient:
|
||||
"""Gets the base url for the request (includes host and path parts, but not query params)."""
|
||||
url_var_suffix = "WS_URL" if is_ws else "URL"
|
||||
url = os.environ.get(f"{self.venue}_{self.mode}_{url_var_suffix}") or ""
|
||||
req_path = Template(os.environ.get(f"{self.venue}_{op}_PATH") or "").substitute(
|
||||
os.environ
|
||||
)
|
||||
req_path = os.environ.get(f"{self.venue}_{op}_PATH") or ""
|
||||
if vars:
|
||||
req_path = Template(req_path).substitute(vars)
|
||||
req_path = expand_vars(req_path, vars)
|
||||
req_path = expand_vars(req_path, os.environ)
|
||||
if req_path:
|
||||
n = 1 if req_path.startswith("/") else 0
|
||||
n += 1 if self.rest_url.endswith("/") else 0
|
||||
@@ -215,6 +213,10 @@ class BinanceClient:
|
||||
url += "?" + params_str
|
||||
if not method:
|
||||
method = "GET"
|
||||
self.logger.info(
|
||||
"Send: %s %s (headers=[%s])"
|
||||
% (method, url, ", ".join([f"{k}={v}" for k, v in headers.items()]))
|
||||
)
|
||||
res = requests.request(method, url, headers=headers)
|
||||
if not res.ok:
|
||||
self.logger.error("Request failed. op=%s, res=\n%s", op, str(res))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from typing import Mapping, Optional
|
||||
import dotenv
|
||||
import os
|
||||
|
||||
@@ -50,7 +50,7 @@ def expand_var(req_params: str, k: str, v: str):
|
||||
return req_params
|
||||
|
||||
|
||||
def expand_vars(req_params: str, key_vals: dict):
|
||||
def expand_vars(req_params: str, key_vals: Mapping):
|
||||
for k, v in key_vals.items():
|
||||
req_params = expand_var(req_params, k, v)
|
||||
return req_params
|
||||
|
||||
Reference in new issue
Block a user