{"id":3946,"date":"2026-11-24T16:36:03","date_gmt":"2026-11-24T07:36:03","guid":{"rendered":"https:\/\/qol-kk.com\/wp2\/?p=3946"},"modified":"2026-11-24T16:36:03","modified_gmt":"2026-11-24T07:36:03","slug":"20261124-plan100","status":"publish","type":"post","link":"https:\/\/qol-kk.com\/wp2\/blog\/2026\/11\/24\/20261124-plan100\/","title":{"rendered":"Python \u3067\u5916\u90e8 API \u3092\u53e9\u304f\uff08httpx \u5165\u9580\uff09"},"content":{"rendered":"<h2>\u3053\u306e\u8a18\u4e8b\u306b\u3064\u3044\u3066<\/h2>\n<p>Python \u3067 HTTP \u901a\u4fe1\u3092\u3059\u308b\u306a\u3089\u3001\u9577\u304f <code>requests<\/code> \u304c\u5b9a\u756a\u3067\u3057\u305f\u3002\u6700\u8fd1\u306f\u3001\u540c\u671f\u3068\u975e\u540c\u671f\u306e\u4e21\u65b9\u3092\u540c\u3058\u66f8\u304d\u65b9\u3067\u6271\u3048\u308b <strong>httpx<\/strong> \u3092\u9078\u3076\u5834\u9762\u304c\u5897\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u306f\u30cf\u30f3\u30ba\u30aa\u30f3\u5f62\u5f0f\u3067\u3001httpx \u306e\u57fa\u672c\u304b\u3089\u5b9f\u52d9\u3067\u5fc5\u8981\u306b\u306a\u308b\u30dd\u30a4\u30f3\u30c8\u307e\u3067\u3092\u9806\u306b\u78ba\u8a8d\u3057\u307e\u3059\u3002\u984c\u6750\u306b\u306f\u3001\u8ab0\u3067\u3082\u53e9\u3051\u308b\u516c\u958b\u306e\u30c0\u30df\u30fc API\u300cJSONPlaceholder\u300d\uff08<code>https:\/\/jsonplaceholder.typicode.com<\/code>\uff09\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u3053\u306e\u8a18\u4e8b\u3067\u5b66\u3079\u308b\u3053\u3068<\/strong><\/p>\n<ol>\n<li>\u6700\u5c0f\u306e GET \u30ea\u30af\u30a8\u30b9\u30c8<\/li>\n<li><code>Client<\/code> \u3092\u4f7f\u3063\u305f\u5b9f\u52d9\u5411\u3051\u306e\u66f8\u304d\u65b9<\/li>\n<li>POST\u30fb\u30af\u30a8\u30ea\u30d1\u30e9\u30e1\u30fc\u30bf\u30fb\u30d8\u30c3\u30c0\u30fb\u8a8d\u8a3c<\/li>\n<li>\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3068\u4f8b\u5916\u51e6\u7406<\/li>\n<li>\u30ea\u30c8\u30e9\u30a4<\/li>\n<li>\u975e\u540c\u671f\uff08<code>AsyncClient<\/code>\uff09\u3067\u306e\u4e26\u5217\u30ea\u30af\u30a8\u30b9\u30c8<\/li>\n<li><code>MockTransport<\/code> \u3092\u4f7f\u3063\u305f\u30c6\u30b9\u30c8<\/li>\n<\/ol>\n<h2>\u74b0\u5883<\/h2>\n<ul>\n<li>Python 3.12\uff083.9 \u4ee5\u4e0a\u306a\u3089\u540c\u3058\u66f8\u304d\u65b9\u3067\u52d5\u304f\u60f3\u5b9a\u3067\u3059\uff09<\/li>\n<li>httpx 0.28 \u7cfb<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">python -m venv .venv\nsource .venv\/bin\/activate\npip install httpx<\/pre>\n<h2>\u306a\u305c httpx \u306a\u306e\u304b<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u89b3\u70b9<\/th>\n<th>requests<\/th>\n<th>httpx<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u540c\u671f API<\/td>\n<td>\u25cb<\/td>\n<td>\u25cb\uff08requests \u3068\u307b\u307c\u540c\u3058\u66f8\u304d\u65b9\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u975e\u540c\u671f API<\/td>\n<td>\u00d7\uff08\u5225\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u5fc5\u8981\uff09<\/td>\n<td>\u25cb <code>AsyncClient<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8<\/td>\n<td>\u306a\u3057\uff08\u7121\u671f\u9650\u306b\u5f85\u3064\uff09<\/td>\n<td>5\u79d2<\/td>\n<\/tr>\n<tr>\n<td>\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u8ffd\u5f93<\/td>\n<td>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u8ffd\u5f93\u3059\u308b<\/td>\n<td>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u8ffd\u5f93\u3057\u306a\u3044<\/td>\n<\/tr>\n<tr>\n<td>HTTP\/2<\/td>\n<td>\u00d7<\/td>\n<td>\u25cb\uff08<code>pip install 'httpx[http2]'<\/code>\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u30c6\u30b9\u30c8\u7528\u306e\u30e2\u30c3\u30af<\/td>\n<td>\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046<\/td>\n<td><code>MockTransport<\/code> \u304c\u6a19\u6e96<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>requests \u304b\u3089\u79fb\u308b\u5834\u5408\u3001<strong>\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3068\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u304c\u9055\u3046<\/strong>\u3053\u3068\u3055\u3048\u62bc\u3055\u3048\u3066\u304a\u3051\u3070\u3001\u5927\u304d\u304f\u30cf\u30de\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d71: \u307e\u305a\u306f GET \u3057\u3066\u307f\u308b<\/h2>\n<pre class=\"lang:default decode:true\">import httpx\n\nr = httpx.get(\"https:\/\/jsonplaceholder.typicode.com\/posts\/1\")\n\nprint(r.status_code)       # 200\nprint(r.headers[\"content-type\"])\nprint(r.json()[\"title\"])   # JSON \u3092 dict \u3068\u3057\u3066\u53d6\u5f97<\/pre>\n<p><code>httpx.get()<\/code> \u306f\u624b\u8efd\u3067\u3059\u304c\u3001\u547c\u3076\u305f\u3073\u306b\u63a5\u7d9a\u3092\u5f35\u308a\u76f4\u3057\u307e\u3059\u30021\u56de\u53e9\u304f\u3060\u3051\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306a\u3089\u3053\u308c\u3067\u5341\u5206\u3067\u3059\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d72: <code>Client<\/code> \u3092\u4f7f\u3046\uff08\u5b9f\u52d9\u306e\u57fa\u672c\u5f62\uff09<\/h2>\n<pre class=\"lang:default decode:true\">import httpx\n\nBASE_URL = \"https:\/\/jsonplaceholder.typicode.com\"\n\nwith httpx.Client(\n    base_url=BASE_URL,\n    timeout=10.0,\n    headers={\"Accept\": \"application\/json\"},\n) as client:\n    r = client.get(\"\/posts\", params={\"userId\": 1})\n    r.raise_for_status()\n    posts = r.json()\n    print(f\"{len(posts)} \u4ef6\u53d6\u5f97\")<\/pre>\n<ul>\n<li><strong><code>base_url<\/code><\/strong>: \u4ee5\u964d\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306f\u76f8\u5bfe\u30d1\u30b9\u3067\u66f8\u3051\u307e\u3059\u3002<\/li>\n<li><strong>\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb<\/strong>: \u540c\u3058 <code>Client<\/code> \u304b\u3089\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306f\u63a5\u7d9a\u3092\u4f7f\u3044\u56de\u3059\u306e\u3067\u3001\u9023\u7d9a\u30ea\u30af\u30a8\u30b9\u30c8\u304c\u901f\u304f\u306a\u308a\u307e\u3059\u3002<\/li>\n<li><strong><code>with<\/code> \u3067\u9589\u3058\u308b<\/strong>: \u63a5\u7d9a\u3092\u78ba\u5b9f\u306b\u89e3\u653e\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<p><code>params<\/code> \u306b\u6e21\u3057\u305f dict \u306f <code>?userId=1<\/code> \u306e\u3088\u3046\u306b URL \u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d73: POST\u30fb\u30d8\u30c3\u30c0\u30fb\u8a8d\u8a3c<\/h2>\n<h3>JSON \u3092 POST \u3059\u308b<\/h3>\n<pre class=\"lang:default decode:true\">with httpx.Client(base_url=BASE_URL, timeout=10.0) as client:\n    r = client.post(\n        \"\/posts\",\n        json={\"title\": \"hello\", \"body\": \"httpx \u304b\u3089\u6295\u7a3f\", \"userId\": 1},\n    )\n    r.raise_for_status()\n    print(r.status_code)  # 201\n    print(r.json())<\/pre>\n<p><code>json=<\/code> \u3092\u4f7f\u3046\u3068\u3001\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3068 <code>Content-Type: application\/json<\/code> \u306e\u4ed8\u4e0e\u3092 httpx \u304c\u3084\u3063\u3066\u304f\u308c\u307e\u3059\u3002\u30d5\u30a9\u30fc\u30e0\u9001\u4fe1\u306f <code>data=<\/code>\u3001\u30d5\u30a1\u30a4\u30eb\u9001\u4fe1\u306f <code>files=<\/code> \u3067\u3059\u3002<\/p>\n<p>\u203b JSONPlaceholder \u306f\u30c0\u30df\u30fc API \u306a\u306e\u3067\u3001POST \u3057\u305f\u30c7\u30fc\u30bf\u306f\u5b9f\u969b\u306b\u306f\u4fdd\u5b58\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<h3>\u8a8d\u8a3c\u30c8\u30fc\u30af\u30f3\u306f\u74b0\u5883\u5909\u6570\u304b\u3089\u8aad\u3080<\/h3>\n<pre class=\"lang:default decode:true\">import os\nimport httpx\n\ntoken = os.environ[\"EXAMPLE_API_TOKEN\"]  # \u4e8b\u524d\u306b\u74b0\u5883\u5909\u6570\u3078\u8a2d\u5b9a\u3057\u3066\u304a\u304f\n\nclient = httpx.Client(\n    base_url=\"https:\/\/api.example.com\",\n    headers={\"Authorization\": f\"Bearer {token}\"},\n    timeout=10.0,\n)<\/pre>\n<p>\u30c8\u30fc\u30af\u30f3\u3084 API \u30ad\u30fc\u306f\u3001\u30b3\u30fc\u30c9\u306b\u76f4\u63a5\u66f8\u304b\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d74: \u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3068\u4f8b\u5916\u51e6\u7406<\/h2>\n<p>\u5916\u90e8 API \u306f\u300c\u9045\u3044\u300d\u300c\u843d\u3061\u3066\u3044\u308b\u300d\u300c4xx\/5xx \u3092\u8fd4\u3059\u300d\u306e\u304c\u5f53\u305f\u308a\u524d\u3068\u8003\u3048\u3066\u66f8\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3092\u7d30\u304b\u304f\u6307\u5b9a\u3059\u308b<\/h3>\n<pre class=\"lang:default decode:true\">timeout = httpx.Timeout(10.0, connect=3.0)  # \u5168\u4f5310\u79d2\u3001\u63a5\u7d9a\u78ba\u7acb\u3060\u30513\u79d2\nclient = httpx.Client(base_url=BASE_URL, timeout=timeout)<\/pre>\n<p><code>connect<\/code> \/ <code>read<\/code> \/ <code>write<\/code> \/ <code>pool<\/code> \u3092\u500b\u5225\u306b\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u4f8b\u5916\u306e\u968e\u5c64<\/h3>\n<pre class=\"lang:default decode:true\">httpx.HTTPError\n\u251c\u2500\u2500 httpx.RequestError          \u2026 \u901a\u4fe1\u81ea\u4f53\u304c\u5931\u6557\uff08DNS\u30fb\u63a5\u7d9a\u30fb\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306a\u3069\uff09\n\u2502   \u2514\u2500\u2500 httpx.TransportError\n\u2502       \u2514\u2500\u2500 httpx.TimeoutException\n\u2514\u2500\u2500 httpx.HTTPStatusError       \u2026 raise_for_status() \u3067 4xx\/5xx \u3092\u691c\u51fa<\/pre>\n<p><strong>httpx \u306f 4xx\/5xx \u3067\u3082\u4f8b\u5916\u3092\u6295\u3052\u307e\u305b\u3093\u3002<\/strong> \u30b9\u30c6\u30fc\u30bf\u30b9\u3067\u4f8b\u5916\u306b\u3057\u305f\u3044\u3068\u304d\u306f <code>raise_for_status()<\/code> \u3092\u660e\u793a\u7684\u306b\u547c\u3073\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">import httpx\n\ndef fetch_post(client: httpx.Client, post_id: int) -&gt; dict | None:\n    try:\n        r = client.get(f\"\/posts\/{post_id}\")\n        r.raise_for_status()\n        return r.json()\n    except httpx.TimeoutException:\n        print(\"\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u307e\u3057\u305f\")\n    except httpx.HTTPStatusError as e:\n        print(f\"HTTP \u30a8\u30e9\u30fc: {e.response.status_code} {e.request.url}\")\n    except httpx.RequestError as e:\n        print(f\"\u901a\u4fe1\u30a8\u30e9\u30fc: {e!r}\")\n    return None\n\nwith httpx.Client(base_url=BASE_URL, timeout=10.0) as client:\n    print(fetch_post(client, 1))\n    print(fetch_post(client, 999999))  # \u5b58\u5728\u3057\u306a\u3044 ID \u2192 404<\/pre>\n<p><code>TimeoutException<\/code> \u306f <code>RequestError<\/code> \u306e\u30b5\u30d6\u30af\u30e9\u30b9\u306a\u306e\u3067\u3001\u3088\u308a\u5177\u4f53\u7684\u306a\u4f8b\u5916\u3092\u5148\u306b\u66f8\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d75: \u30ea\u30c8\u30e9\u30a4<\/h2>\n<h3>\u63a5\u7d9a\u30a8\u30e9\u30fc\u306e\u30ea\u30c8\u30e9\u30a4<\/h3>\n<pre class=\"lang:default decode:true\">transport = httpx.HTTPTransport(retries=3)\nclient = httpx.Client(base_url=BASE_URL, transport=transport, timeout=10.0)<\/pre>\n<p>\u3053\u306e <code>retries<\/code> \u304c\u518d\u8a66\u884c\u3059\u308b\u306e\u306f<strong>\u63a5\u7d9a\u78ba\u7acb\u306e\u5931\u6557\uff08<code>ConnectError<\/code> \/ <code>ConnectTimeout<\/code>\uff09\u3060\u3051<\/strong>\u3067\u3059\u3002429 \u3084 503 \u3067\u306f\u518d\u8a66\u884c\u3057\u307e\u305b\u3093\u3002<\/p>\n<h3>\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3067\u306e\u30ea\u30c8\u30e9\u30a4<\/h3>\n<pre class=\"lang:default decode:true\">import time\nimport httpx\n\nRETRY_STATUSES = {429, 500, 502, 503, 504}\n\ndef get_with_retry(client: httpx.Client, url: str, max_attempts: int = 3) -&gt; httpx.Response:\n    for attempt in range(1, max_attempts + 1):\n        try:\n            r = client.get(url)\n            if r.status_code not in RETRY_STATUSES:\n                r.raise_for_status()\n                return r\n        except httpx.TransportError:\n            if attempt == max_attempts:\n                raise\n        if attempt == max_attempts:\n            r.raise_for_status()\n        time.sleep(2 ** (attempt - 1))  # 1\u79d2, 2\u79d2, 4\u79d2...\n    raise RuntimeError(\"unreachable\")<\/pre>\n<p>\u672c\u683c\u7684\u306b\u4f7f\u3046\u306a\u3089 <code>tenacity<\/code> \u306a\u3069\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u306e\u3082\u3088\u3044\u3067\u3059\u3002\u3044\u305a\u308c\u306e\u65b9\u6cd5\u3067\u3082\u3001<strong>POST \u306e\u3088\u3046\u306b\u51aa\u7b49\u3067\u306a\u3044\u30ea\u30af\u30a8\u30b9\u30c8\u306f\u7121\u6761\u4ef6\u306b\u30ea\u30c8\u30e9\u30a4\u3057\u306a\u3044<\/strong>\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u30b9\u30c6\u30c3\u30d76: \u975e\u540c\u671f\u3067\u4e26\u5217\u30ea\u30af\u30a8\u30b9\u30c8<\/h2>\n<pre class=\"lang:default decode:true\">import asyncio\nimport httpx\n\nBASE_URL = \"https:\/\/jsonplaceholder.typicode.com\"\n\nasync def main() -&gt; None:\n    async with httpx.AsyncClient(base_url=BASE_URL, timeout=10.0) as client:\n        tasks = [client.get(f\"\/posts\/{i}\") for i in range(1, 11)]\n        responses = await asyncio.gather(*tasks)\n\n    for r in responses:\n        r.raise_for_status()\n        print(r.json()[\"id\"], r.json()[\"title\"][:30])\n\nasyncio.run(main())<\/pre>\n<p>\u76f8\u624b\u306e API \u306b\u30ec\u30fc\u30c8\u5236\u9650\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u540c\u6642\u5b9f\u884c\u6570\u3092\u7d5e\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">async def fetch_all(ids: list[int], limit: int = 5) -&gt; list[dict]:\n    sem = asyncio.Semaphore(limit)\n\n    async with httpx.AsyncClient(base_url=BASE_URL, timeout=10.0) as client:\n        async def fetch(i: int) -&gt; dict:\n            async with sem:\n                r = await client.get(f\"\/posts\/{i}\")\n                r.raise_for_status()\n                return r.json()\n\n        return await asyncio.gather(*(fetch(i) for i in ids))<\/pre>\n<h2>\u30b9\u30c6\u30c3\u30d77: <code>MockTransport<\/code> \u3067\u30c6\u30b9\u30c8\u3059\u308b<\/h2>\n<pre class=\"lang:default decode:true\">import httpx\n\ndef get_title(client: httpx.Client, post_id: int) -&gt; str:\n    r = client.get(f\"\/posts\/{post_id}\")\n    r.raise_for_status()\n    return r.json()[\"title\"]\n\n\ndef test_get_title() -&gt; None:\n    def handler(request: httpx.Request) -&gt; httpx.Response:\n        assert request.url.path == \"\/posts\/1\"\n        return httpx.Response(200, json={\"id\": 1, \"title\": \"mocked\"})\n\n    client = httpx.Client(\n        base_url=\"https:\/\/example.com\",\n        transport=httpx.MockTransport(handler),\n    )\n    assert get_title(client, 1) == \"mocked\"\n\n\ndef test_get_title_404() -&gt; None:\n    client = httpx.Client(\n        base_url=\"https:\/\/example.com\",\n        transport=httpx.MockTransport(lambda req: httpx.Response(404)),\n    )\n    try:\n        get_title(client, 1)\n        assert False, \"\u4f8b\u5916\u304c\u51fa\u308b\u306f\u305a\"\n    except httpx.HTTPStatusError as e:\n        assert e.response.status_code == 404<\/pre>\n<p><code>Client<\/code> \u3092\u95a2\u6570\u306e\u5916\u304b\u3089\u53d7\u3051\u53d6\u308b\u8a2d\u8a08\u306b\u3057\u3066\u304a\u3051\u3070\u3001\u30c6\u30b9\u30c8\u3067\u306f\u30e2\u30c3\u30af\u4ed8\u304d\u306e <code>Client<\/code> \u3092\u6e21\u3059\u3060\u3051\u3067\u6e08\u307f\u307e\u3059\u3002<\/p>\n<h2>\u78ba\u8a8d\u65b9\u6cd5<\/h2>\n<ul>\n<li>\u30b9\u30c6\u30c3\u30d71\u301c2\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u3001<code>200<\/code> \u3084\u30bf\u30a4\u30c8\u30eb\u30fb\u4ef6\u6570\u304c\u8868\u793a\u3055\u308c\u308b\u3053\u3068<\/li>\n<li><code>fetch_post(client, 999999)<\/code> \u3067 <code>HTTP \u30a8\u30e9\u30fc: 404<\/code> \u304c\u8868\u793a\u3055\u308c\u308b\u3053\u3068<\/li>\n<li><code>timeout=0.001<\/code> \u306b\u5909\u3048\u3066\u3001\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306e\u5206\u5c90\u306b\u5165\u308b\u3053\u3068<\/li>\n<li><code>pip install pytest<\/code> \u306e\u3042\u3068 <code>pytest<\/code> \u3092\u5b9f\u884c\u3057\u3001\u30c6\u30b9\u30c8\u304c\u901a\u308b\u3053\u3068<\/li>\n<\/ul>\n<h2>\u6ce8\u610f\u70b9<\/h2>\n<ul>\n<li><strong>\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306f5\u79d2\u3002<\/strong> \u91cd\u3044 API \u3067\u306f\u660e\u793a\u7684\u306b\u5ef6\u3070\u3057\u307e\u3059\u3002<code>timeout=None<\/code> \u306b\u3059\u308b\u3068\u7121\u671f\u9650\u306b\u5f85\u3061\u307e\u3059\u3002<\/li>\n<li><strong>\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u8ffd\u5f93\u3057\u306a\u3044\u3002<\/strong> \u5fc5\u8981\u306a\u3089 <code>follow_redirects=True<\/code> \u3092\u4ed8\u3051\u307e\u3059\u3002<\/li>\n<li><strong>4xx\/5xx \u3067\u306f\u4f8b\u5916\u306b\u306a\u3089\u306a\u3044\u3002<\/strong> <code>raise_for_status()<\/code> \u3092\u547c\u3073\u307e\u3059\u3002<\/li>\n<li><strong><code>Client<\/code> \u306f\u4f7f\u3044\u56de\u3059\u3002<\/strong> \u30eb\u30fc\u30d7\u306e\u4e2d\u3067 <code>httpx.get()<\/code> \u3092\u6bce\u56de\u547c\u3070\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/li>\n<li><strong>\u30c8\u30fc\u30af\u30f3\u3084 API \u30ad\u30fc\u3092\u30b3\u30fc\u30c9\u3084\u30ed\u30b0\u306b\u51fa\u3055\u306a\u3044\u3002<\/strong> \u4f8b\u5916\u30e1\u30c3\u30bb\u30fc\u30b8\u306b URL \u304c\u542b\u307e\u308c\u308b\u5834\u5408\u3001\u30af\u30a8\u30ea\u306b\u542b\u3081\u305f\u30ad\u30fc\u304c\u30ed\u30b0\u306b\u6b8b\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n<h2>\u307e\u3068\u3081<\/h2>\n<ul>\n<li>\u624b\u8efd\u306b\u53e9\u304f\u306a\u3089 <code>httpx.get()<\/code>\u3001\u5b9f\u52d9\u3067\u306f <code>httpx.Client<\/code> \u3092 <code>with<\/code> \u3067\u4f7f\u3046<\/li>\n<li>\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u30fb<code>raise_for_status()<\/code>\u30fb\u4f8b\u5916\u306e\u968e\u5c64\u3092\u6700\u521d\u306b\u62bc\u3055\u3048\u308b<\/li>\n<li>\u63a5\u7d9a\u5931\u6557\u306e\u30ea\u30c8\u30e9\u30a4\u306f <code>HTTPTransport(retries=...)<\/code>\u3001\u30b9\u30c6\u30fc\u30bf\u30b9\u3067\u306e\u30ea\u30c8\u30e9\u30a4\u306f\u81ea\u524d\u307e\u305f\u306f\u30e9\u30a4\u30d6\u30e9\u30ea\u3067<\/li>\n<li>\u975e\u540c\u671f\u306f <code>AsyncClient<\/code> \u306b\u7f6e\u304d\u63db\u3048\u308b\u3060\u3051\u3002\u540c\u6642\u5b9f\u884c\u6570\u306f <code>Semaphore<\/code> \u3067\u5236\u5fa1\u3059\u308b<\/li>\n<li>\u30c6\u30b9\u30c8\u306f <code>MockTransport<\/code> \u3067\u3001\u5916\u90e8\u306b\u901a\u4fe1\u305b\u305a\u306b\u66f8\u3051\u308b<\/li>\n<\/ul>\n<p>requests \u306b\u6163\u308c\u3066\u3044\u308c\u3070\u3001\u79fb\u884c\u306e\u30cf\u30fc\u30c9\u30eb\u306f\u9ad8\u304f\u3042\u308a\u307e\u305b\u3093\u3002\u307e\u305a\u306f\u624b\u5143\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306e1\u672c\u3092 <code>httpx.Client<\/code> \u306b\u7f6e\u304d\u63db\u3048\u308b\u3068\u3053\u308d\u304b\u3089\u59cb\u3081\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u3067 HTTP \u901a\u4fe1\u3092\u3059\u308b\u306a\u3089\u3001\u9577\u304f requests \u304c\u5b9a\u756a\u3067\u3057\u305f\u3002\u6700\u8fd1\u306f\u3001\u540c\u671f\u3068\u975e\u540c\u671f\u306e\u4e21\u65b9\u3092\u540c\u3058\u66f8\u304d\u65b9\u3067\u6271\u3048\u308b httpx \u3092\u9078\u3076\u5834\u9762\u304c\u5897\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":3945,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","_lightning_design_setting":[],"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[38],"tags":[64,147,424,163,1188,410,1162],"class_list":["post-3946","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-memorandum","tag-api","tag-python","tag-424","tag-163","tag-1188","tag-410","tag-1162"],"veu_head_title_object":{"title":"","add_site_title":""},"jetpack_publicize_connections":[],"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/qol-kk.com\/wp2\/wp-content\/uploads\/2026\/11\/20261124-plan100-thumbnail.jpg","_links":{"self":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/3946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/comments?post=3946"}],"version-history":[{"count":1,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/3946\/revisions"}],"predecessor-version":[{"id":3947,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/3946\/revisions\/3947"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media\/3945"}],"wp:attachment":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media?parent=3946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/categories?post=3946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/tags?post=3946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}