MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / request_json

Function request_json

scripts/issue_duplicate_check_openhands.py:97–125  ·  view source on GitHub ↗
(
    base_url: str,
    path: str,
    *,
    method: str = 'GET',
    headers: dict[str, str] | None = None,
    body: dict[str, Any] | None = None,
)

Source from the content-addressed store, hash-verified

95
96
97def request_json(
98 base_url: str,
99 path: str,
100 *,
101 method: str = 'GET',
102 headers: dict[str, str] | None = None,
103 body: dict[str, Any] | None = None,
104) -> Any:
105 data = json.dumps(body).encode('utf-8') if body is not None else None
106 request = urllib.request.Request(
107 f'{base_url}{path}',
108 data=data,
109 headers=headers or {},
110 method=method,
111 )
112 try:
113 with urllib.request.urlopen(request, timeout=60) as response:
114 return json.load(response)
115 except urllib.error.HTTPError as exc:
116 error_body = exc.read().decode('utf-8', errors='replace')
117 raise RuntimeError(
118 f'{method} {base_url}{path} failed with HTTP {exc.code}: {error_body}'
119 ) from exc
120 except json.JSONDecodeError as exc:
121 raise RuntimeError(
122 f'Failed to parse JSON from {method} {base_url}{path}: {exc}'
123 ) from exc
124 except urllib.error.URLError as exc:
125 raise RuntimeError(f'{method} {base_url}{path} failed: {exc}') from exc
126
127
128def fetch_issue(repository: str, issue_number: int) -> dict[str, Any]:

Callers 7

fetch_issueFunction · 0.70
start_conversationFunction · 0.70
poll_start_taskFunction · 0.70
poll_conversationFunction · 0.70
fetch_app_server_eventsFunction · 0.70

Calls 2

loadMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected