{"id":295,"date":"2018-10-25T18:17:07","date_gmt":"2018-10-25T10:17:07","guid":{"rendered":"http:\/\/www.yinyubo.cn\/?p=295"},"modified":"2022-05-17T09:45:24","modified_gmt":"2022-05-17T01:45:24","slug":"requestpost","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=295","title":{"rendered":"python\u4f7f\u7528request\u5e93\u53d1\u9001\u4e0a\u4f20zip\u6587\u4ef6\u7684post\u8bf7\u6c42"},"content":{"rendered":"<h1>\u4f7f\u7528\u5de5\u5177\uff1a<\/h1>\n<ul>\n<li>python\uff082.7\uff09<\/li>\n<li>requests\uff082.18.4\uff09<\/li>\n<li>zip\u6587\u4ef6\u4e00\u4e2a<\/li>\n<li>chrome\u6d4f\u89c8\u5668<\/li>\n<\/ul>\n<h1>\u7b2c\u4e00\u6b65\uff0c\u901a\u8fc7chrome\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u8005\u5de5\u5177\uff0c\u83b7\u5f97\u53d1\u9001\u7684\u53c2\u6570\u3002<\/h1>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-296 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-2.png\" alt=\"\" width=\"1137\" height=\"663\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-297 size-large\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/3-1-1024x532.png\" alt=\"\" width=\"900\" height=\"468\" \/><\/p>\n<h1>\u7b2c\u4e8c\u6b65\uff0c\u7f16\u5199python\u4ee3\u7801<\/h1>\n<p>\u4f7f\u7528request\u5e93\u7684post\u65b9\u6cd5\u3002\u6ce8\u610f\u7684\u662f\u8981\u6dfb\u52a0files\u53c2\u6570,\u4f8b\u5982\uff1a<\/p>\n<pre class=\"\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">files ={'app_filename':open('portal-1.0-SNAPSHOT-fat.jar.zip','rb')}<\/code><\/pre>\n<p>zip\u538b\u7f29\u5305\u7528\u7684\u540e\u7f00\u662fapplication\/x-zip-compressed\uff0c\u5176\u4ed6\u7684\u6587\u4ef6\u662fapplication\/octet-stream<br \/>\n\u5176\u4e2d\uff0c&#8217;app_filename&#8217;\u662fF12\u5de5\u5177\u91cc\u6293\u51fa\u6765\u7684from data\u91cc\u7684\u6807\u6709{binary}\u8fd9\u4e00\u884c\u7684\u53c2\u6570\u540d\u3002<br \/>\nportal-1.0-SNAPSHOT-fat.jar.zip\u662f\u6211\u81ea\u5df1\u7535\u8111\u672c\u5730\u7684\u4e00\u4e2azip\u6587\u4ef6\u3002<br \/>\nrb\u662f\u8bfb\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002\u56e0\u4e3a\u8fd9\u4e2aform data\u662f\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u4e0a\u4f20\u6587\u4ef6\u7684<br \/>\n\u5176\u4f59\u7684\u5e38\u89c4\u53c2\u6570\uff0c\u653e\u5230data\u53c2\u6570\u91cc\u3002\u4f8b\u5982\u4e0a\u56fe\u7684image_name:fff\u5c31\u662f\u5e38\u89c4\u53c2\u6570\u3002<br \/>\n\u5728header\u91cc\u6ce8\u610f\u6dfb\u52a0cookies\u503c\u6216\u8005Authorization\u503c\uff0c\u8fd9\u91cc\u6211\u6d4b\u8bd5\u7684\u7f51\u7ad9\u7528\u7684\u662fAuthorization\u3002\u5982\u679c\u6ca1\u6709\u8be5\u53c2\u6570\uff0c\u4f1a\u8fd4\u56de401<br \/>\n\u5b8c\u6574python request\u4f53\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:python decode:true\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">path = os.path.split(os.path.realpath(__file__))[0]\nurl = host + '\/dashboard\/cicd\/images'\nheaders = {\n    'Authorization':'6bae7b70-8dae-4f74-9631-680b9501b52',\n    'cookie': \"_ga=GA1.3.733851079.1534745675; Hm_lvt_dde6ba2851f3db0ddc415ce0f895822e=1537859803; _ga=GA1.3.733851079.1534745675; Hm_lvt_dde6ba2851f3db0ddc415ce0f895822e=1537859803\",\n}\ndatat = {'image_name': 'abcd',\n         'image_description': 'ccccvcc',\n         'image_label': '1cc1fcc',\n         'basic_image': 'openjdk:10',\n         'store_path': '\/opt\/app\/lzw\/'}\nfiles = {'app_filename': (\n    'portal-1.0-SNAPSHOT-fat.jar.zip', open(os.path.join(path, 'portal-1.0-SNAPSHOT-fat.jar.zip'), 'rb'),\n    'application\/x-zip-compressed')}\n# files ={'app_filename':open('portal-1.0-SNAPSHOT-fat.jar.zip','rb')} \u548c\u4e0a\u9762\u7684\u529f\u80fd\u4e00\u6837\nresult = requests.post(url, files=files, data=datat, headers=headers)\nr1 = result.text\nprint(result.text)<\/code><\/pre>\n<p><span style=\"color: #ff6600;\">\u6ce8\u610f\uff1a\u5343\u4e07\u4e0d\u8981\u5728head\u91cc\u52a0\u5165\u00a0&#8216;Content-Type&#8217;:&#8217;multipart\/form-data;\u53c2\u6570\u3002<\/span><\/p>\n<h1><\/h1>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u5de5\u5177\uff1a python\uff082.7\uff09 requests\uff082.18.4\uff09 zip\u6587\u4ef6\u4e00\u4e2a chrome\u6d4f\u89c8\u5668 \u7b2c\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-295","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=295"}],"version-history":[{"count":1,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/295\/revisions"}],"predecessor-version":[{"id":944,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/295\/revisions\/944"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}