fix: remove stale _decimal_str ref, add context manager to HTTP clients
- UpstreamClient & Sub2ApiWebsiteClient: add __enter__/__exit__ - Convert all call sites to `with Client(...) as c:` pattern - Remove unused `upstream_name`/`upstream_base_url` locals in scheduler - Fix stale _decimal_str→decimal_string in _rate_from_group
This commit is contained in:
+18
-18
@@ -6,31 +6,31 @@ from app.services.upstream_client import UpstreamClient
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
def main():
|
||||
client = UpstreamClient(
|
||||
with UpstreamClient(
|
||||
base_url="http://170.106.100.210:55555",
|
||||
api_prefix="",
|
||||
auth_type="bearer",
|
||||
auth_config={"token": ""}, # We don't have token, but /api/group/ in some new-api may be open, or fail with 401
|
||||
timeout=10.0,
|
||||
)
|
||||
try:
|
||||
groups = client.get_available_groups("/api/group/")
|
||||
print("Groups:", groups)
|
||||
except Exception as e:
|
||||
print("Groups Error:", e)
|
||||
) as client:
|
||||
try:
|
||||
groups = client.get_available_groups("/api/group/")
|
||||
print("Groups:", groups)
|
||||
except Exception as e:
|
||||
print("Groups Error:", e)
|
||||
|
||||
try:
|
||||
rates = client.get_group_rates("/api/option/?key=GroupRatio")
|
||||
print("Rates:", rates)
|
||||
except Exception as e:
|
||||
print("Rates Error:", e)
|
||||
try:
|
||||
rates = client.get_group_rates("/api/option/?key=GroupRatio")
|
||||
print("Rates:", rates)
|
||||
except Exception as e:
|
||||
print("Rates Error:", e)
|
||||
|
||||
try:
|
||||
from app.services.upstream_client import _extract_rates_map, _unwrap_list
|
||||
print("Unwrapped Groups:", _unwrap_list(groups))
|
||||
print("Extracted Rates:", _extract_rates_map(rates))
|
||||
except Exception as e:
|
||||
pass
|
||||
try:
|
||||
from app.services.upstream_client import _extract_rates_map, _unwrap_list
|
||||
print("Unwrapped Groups:", _unwrap_list(groups))
|
||||
print("Extracted Rates:", _extract_rates_map(rates))
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user