{"id":419023,"date":"2021-03-22T00:01:20","date_gmt":"2021-03-21T16:01:20","guid":{"rendered":"http:\/\/4563.org\/?p=419023"},"modified":"2021-03-22T00:01:20","modified_gmt":"2021-03-21T16:01:20","slug":"%e6%b1%82%e6%95%99%e4%b8%80%e4%b8%aa-python-%e5%85%b3%e4%ba%8e-form-data-%e7%9a%84%e6%95%b0%e6%8d%ae%e6%80%8e%e4%b9%88%e9%80%9a%e8%bf%87-requests-post-%e4%b8%8a%e4%bc%a0","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=419023","title":{"rendered":"\u6c42\u6559\u4e00\u4e2a Python \u5173\u4e8e form-data \u7684\u6570\u636e\u600e\u4e48\u901a\u8fc7 requests.post \u4e0a\u4f20"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6c42\u6559\u4e00\u4e2a Python \u5173\u4e8e form-data \u7684\u6570\u636e\u600e\u4e48\u901a\u8fc7 requests.post \u4e0a\u4f20               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wkx556874 <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u60f3\u5199\u4e00\u4e2a\u722c\u866b\u81ea\u52a8\u63d0\u4ea4\u4fee\u6539\u67d0\u5e73\u53f0\u7684\u4eba\u5458\u4fe1\u606f\uff0c<br \/>\u6240\u6709\u4fe1\u606f\u90fd\u641e\u61c2\u4e86\uff0c\u4f46\u662f\u6709\u4e00\u9879\u662f\u7167\u7247\u3002<br \/>\u5176\u4ed6\u4f8b\u5982\u624b\u673a\u53f7\u90a3\u4e9b\u6570\u636e\u76f4\u63a5\u5728 data \u5b57\u5178\u91cc\u9762\u58f0\u660e data={&#8220;mobile&#8221;\uff1a&#8221;13000000000&#8221;}\u5c31\u884c\uff0c<br \/>\u8fd9\u662f\u6293\u5305\u6293\u5230\u7684\u6570\u636e\uff1a<br \/>Content-Disposition: form-data; name=&#8221;mobile&#8221;<br \/>Content-Length: 11 13000000000<br \/>\u7136\u540e\u76f4\u63a5 session.post(url, data=data) \u5c31\u76f4\u63a5\u4fee\u6539\u4e86\uff0c<br \/>\u4f46\u662f\u7167\u7247\u5e94\u8be5\u600e\u4e48\u5f04\u5462\uff1f<br \/>\u8fd9\u662f\u6293\u5305\u6293\u5230\u7684\u6570\u636e\uff1a<br \/>Content-Disposition: form-data; name=&#8221;photo&#8221;; filename=&#8221;pic_after_crop_20210328145606.jpg&#8221;<br \/>Content-Type: multipart\/mixed; boundary=BbC04y<br \/>Content-Length: 205722 &lt;file&gt;<br \/>\u6211\u8fd9\u6837\u5199\uff0c\u4fee\u6539\u6ca1\u7528\u3002\u3002<br \/>files = {&#8220;file&#8221;: (&#8220;1.png&#8221;, open(&#8220;1.png&#8221;, &#8220;rb&#8221;), &#8220;image\/png&#8221;)}<br \/>data={&#8220;photo&#8221;: &#8220;1.png&#8221;}<br \/>session.post(url, data=data, files=files)<br \/>\u5e94\u8be5\u600e\u4e48\u5199\u5462\uff1f\u6211\u67e5\u4e86\u5f88\u591a\u6587\u6863\u4e5f\u6ca1\u627e\u5230\u3002\u3002<br \/>\u53ea\u597d\u6765\u95ee\u95ee\u5927\u4f6c\u4eec\u3002      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5591790\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wkx556874 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u641e\u4e0d\u61c2\u5440\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591791\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ch2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             requests \u4e5f\u4e0d\u662f\u4ec0\u4e48\u5f62\u5f0f\u7684\u8bf7\u6c42\u90fd\u80fd\u5f88\u7b80\u5355\u5c31\u53d1\u51fa\u53bb\u7684\u3002http \u672c\u8d28\u4e0a\u662f\u4e2a\u5b57\u7b26\u4e32\u6784\u9020\u534f\u8bae\uff0c\u4f60\u81ea\u5df1\u62fc\u63a5\u4e00\u4e2a body\uff0c\u7136\u540e requests.post(url,data=body)\u5c31\u884c\u4e86\uff0c\u7136\u540e\u641e\u4e2a fiddler web debugger \u770b\u770b\u62a5\u6587\u6784\u9020\u7684\u5bf9\u4e0d\u5bf9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591792\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 676529483 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &gt;&gt;&gt; url = &#8216;https:\/\/httpbin.org\/post&#8217;<br \/>&gt;&gt;&gt; files = {&#8216;file&#8217;: (&#8220;1.png&#8221;, open(&#8216;1.png&#8217;, &#8216;rb&#8217;)), &#8220;photo&#8221;: &#8220;1.png&#8221;}<\/p>\n<p>&gt;&gt;&gt; r = requests.post(url, files=files)<br \/>\u5173\u952e\u662f data \u548c files \u4e0d\u8981\u4e00\u8d77\u4f20\uff0c\u4f1a\u9ed8\u8ba4 content-type \u4e3a www-url-encode                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591793\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SenLief <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b98\u7f51\u6709 https:\/\/www.osgeo.cn\/requests\/user\/quickstart.html#more-complicated-post-requests<br \/>\u5c0f\u6587\u4ef6\u53ef\u4ee5\u7528\u4e0a 3 \u7684 files \u53c2\u6570\uff0c<br \/>\u5927\u6587\u4ef6\u9700\u8981\u4e00\u4e2a\u4e00\u4e2a\u5305 requests-toolbelt                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591794\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : renmu123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u76f4\u63a5 post \u6587\u4ef6\uff0c\u6216\u8005\u7528 file \u53c2\u6570\uff0c\u4f46\u662f\u4f60\u53ef\u80fd\u8981\u624b\u52a8\u4fee\u6539 contetn-type \u53c2\u6570                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591795\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cra2y4ngel <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             requests \u5728\u63d0 multi-part\/form-data \u4e0a\u9762\u662f\u6709\u4e9b\u8bb8\u7f3a\u9677\u7684\uff0c \u53ef\u4ee5\u901a\u8fc7\u8fd9\u6837\u7684\u65b9\u5f0f\u4f20 data \u770b\u770b<\/p>\n<p>data = {&#8220;photo&#8221;: &#8220;1.png&#8221;}<\/p>\n<p>files = {<br \/>&#8220;file&#8221;: (&#8220;1.png&#8221;, open(&#8220;1.png&#8221;, &#8220;rb&#8221;), &#8220;image\/png&#8221;),<br \/>&#8220;data&#8221;:(None, json.dumps(data))<br \/>}<\/p>\n<p>requests.post(url=url, file=files)                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591796\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : daxin945 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u53ef\u4ee5\u7528 postman \u5c1d\u8bd5\u53d1\u8d77\u8bf7\u6c42\uff0c\u64cd\u4f5c\u6210\u529f\u540e\u80fd\u76f4\u63a5\u5bfc\u51fa\u4ee3\u7801                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591797\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : k1z <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/www.dazhuanlan.com\/2019\/12\/09\/5dee54bde48f4\/<br \/>\u521a\u597d\u4e4b\u524d\u9047\u5230\u8fc7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591798\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Latin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/stackoverflow.com\/questions\/51349340\/recreate-post-request-with-webkitformboundary-using-pythons-requests <br \/>stackoverflow \u89e3\u541b\u5fe7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5591799\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/curl.trillworks.com\/ \u89e3\u541b\u6101                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u6559\u4e00\u4e2a Python \u5173\u4e8e fo&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/419023"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=419023"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/419023\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=419023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=419023"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=419023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}