Skip to content

Commit

Permalink
Use with requests.Session
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Nov 5, 2023
1 parent 4a5b941 commit 67cdb4b
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions services/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import os
from contextlib import closing
from functools import cache
from typing import Any

Expand Down Expand Up @@ -71,13 +70,11 @@ def guess_service2(server: str) -> Any | None:
"HEAD": ((MyRedmine, "issues.json", 200),),
}

session = requests.Session()
session.headers["Accept"] = "application/json"
session.verify = os.environ.get("REQUESTS_CA_BUNDLE", True)
if os.getenv("DEBUG"):
session.hooks["response"].append(debugme)

with closing(session):
with requests.Session() as session:
session.headers["Accept"] = "application/json"
session.verify = os.environ.get("REQUESTS_CA_BUNDLE", True)
if os.getenv("DEBUG"):
session.hooks["response"].append(debugme)
for method, want in endpoints.items():
for cls, endpoint, status in want:
url = f"https://{server}/{endpoint}"
Expand Down

0 comments on commit 67cdb4b

Please sign in to comment.