MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / http_json

Function http_json

deployments/feishu/webhook-server/start-with-ngrok.py:76–93  ·  view source on GitHub ↗
(
    method: str,
    url: str,
    payload: dict[str, Any] | None = None,
    timeout: float = 3.0,
)

Source from the content-addressed store, hash-verified

74
75
76def http_json(
77 method: str,
78 url: str,
79 payload: dict[str, Any] | None = None,
80 timeout: float = 3.0,
81) -> dict[str, Any] | None:
82 data = None
83 headers = {}
84 if payload is not None:
85 data = json.dumps(payload).encode("utf-8")
86 headers["Content-Type"] = "application/json"
87
88 request = urllib.request.Request(url, data=data, method=method, headers=headers)
89 try:
90 with urllib.request.urlopen(request, timeout=timeout) as response:
91 return json.loads(response.read().decode("utf-8"))
92 except (urllib.error.URLError, TimeoutError, json.JSONDecodeError):
93 return None
94
95
96def ngrok_api_get(path: str) -> dict[str, Any] | None:

Callers 3

ngrok_api_getFunction · 0.85
ngrok_api_postFunction · 0.85
ngrok_api_deleteFunction · 0.85

Calls 3

encodeMethod · 0.80
decodeMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected