{"id":5434,"date":"2024-01-19T11:07:01","date_gmt":"2024-01-19T02:07:01","guid":{"rendered":"https:\/\/www.searchlight8.com\/?p=5434"},"modified":"2024-01-19T11:07:01","modified_gmt":"2024-01-19T02:07:01","slug":"python-urllib3","status":"publish","type":"post","link":"https:\/\/www.searchlight8.com\/wp-searchlight8\/python-urllib3\/","title":{"rendered":"[Python] URLlib3\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"\n<p>urllib3\u306fPython\u7528\u306eHTTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3067\u3001Python\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3088\u308a\u591a\u304f\u306e\u6a5f\u80fd\u3092\u642d\u8f09\u3057\u3066\u3044\u307e\u3059\u3002MIT\u30e9\u30a4\u30bb\u30f3\u30b9\u306e\u5143\u3067\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">urllib3\u306e\u30a4\u30f3\u30dd\u30fc\u30c8<\/h3>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" >\/\/ubuntu\u306e\u5834\u5408\n$ sudo apt install urllib3\n\n\/\/pip\u3067\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306e\u5834\u5408\n$ pip install urllib3<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u4f5c\u6210<\/h3>\n\n\n\n<p>urllib3\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3066\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" >import urllib3\nhttp = urllib3.PoolManager()<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u4f5c\u6210<\/h3>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" >url = 'https:\/\/www.example.com'\nresponse = http.request('GET', url)\nprint(response.data.decode('utf-8'))<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Basic\u8a8d\u8a3c\u3067ID\/PASS\u3092\u81ea\u52d5\u5165\u529b\u3059\u308b\u4f8b<\/h3>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" >id = \"ID\u3092\u5165\u529b\"\npw = \"Password\u3092\u5165\u529b\"\n\nimport urllib3\nhttp = urllib3.PoolManager()\n\nurl = \"https:\/\/www.example.com\"\nheaders = urllib3.util.make_headers(basic_auth=\"%s:%s\" % (id, pw) )\nresponse = http.request(\"GET\", url, headers=headers)\n\n\/\/\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\nf = open(\"test.csv\", \"wb\")\nf.write(response.data)\nf.close()\n\n\/\/\u5358\u7d14\u306b\u8868\u793a\nprint(response.data.decode('utf-8'))<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>urllib3\u306fPython\u7528\u306eHTTP&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4567,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[321],"tags":[439],"class_list":["post-5434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-urllib3","wpcat-321-id"],"_links":{"self":[{"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/posts\/5434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/comments?post=5434"}],"version-history":[{"count":12,"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/posts\/5434\/revisions"}],"predecessor-version":[{"id":5446,"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/posts\/5434\/revisions\/5446"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/media\/4567"}],"wp:attachment":[{"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/media?parent=5434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/categories?post=5434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchlight8.com\/wp-searchlight8\/wp-json\/wp\/v2\/tags?post=5434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}