http - python requests上传文件问题
怪我咯
怪我咯 2017-04-18 10:34:04
0
1
407
headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:255
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryAAAuEGgBgQABXetS

Request Payload
------WebKitFormBoundaryAAAuEGgBgQABXetS
Content-Disposition: form-data; name="file"; filename="67.pdf"
Content-Type: application/pdf


------WebKitFormBoundaryAAAuEGgBgQABXetS--
files = {'Filename':'67.pdf',

        'file':('67.pdf',open(r'C:\Users\john\Desktop\67.pdf','rb'),'application/octet-stream'),

        'Upload':'Submit Query'

}
html=requests.post(url=url,headers=headers,files=files)
print (html.status_code)
print (html.text)

像这样post会报错

TypeError: Cannot read property &#39;path&#39; of undefined<br> &nbsp; &nbsp;at /u/apps/jibe-apply-app_4.0.41_master/server/routes/api/apply/upload.js:96:33<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at next (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/route.js:131:13)<br> &nbsp; &nbsp;at /u/apps/jibe-apply-app_4.0.41_master/server/middleware/statsd.js:40:7<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at next (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/route.js:131:13)<br> &nbsp; &nbsp;at module.exports (/u/apps/jibe-apply-app_4.0.41_master/server/middleware/requireUser.js:6:5)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at next (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/route.js:131:13)<br> &nbsp; &nbsp;at Route.dispatch (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/route.js:112:3)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at /u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:277:22<br> &nbsp; &nbsp;at Function.process_params (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:330:12)<br> &nbsp; &nbsp;at next (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:271:10)<br> &nbsp; &nbsp;at expressInit (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/middleware/init.js:33:5)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at trim_prefix (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:312:13)<br> &nbsp; &nbsp;at /u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:280:7<br> &nbsp; &nbsp;at Function.process_params (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:330:12)<br> &nbsp; &nbsp;at next (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:271:10)<br> &nbsp; &nbsp;at query (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/middleware/query.js:44:5)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at trim_prefix (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:312:13)<br> &nbsp; &nbsp;at /u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:280:7<br> &nbsp; &nbsp;at Function.process_params (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:330:12)<br> &nbsp; &nbsp;at next (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:271:10)<br> &nbsp; &nbsp;at Function.handle (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/router/index.js:176:3)<br> &nbsp; &nbsp;at EventEmitter.handle (/u/apps/jibe-apply-app_4.0.41_master/node_modules/express/lib/application.js:173:10)

但是如果把payload里的内容复制下来,粘贴到某个文件,post这个文件,反而不会有这个错误。requests不要post这个文件的内容么?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
Ty80

Done!
files = {

    'file':open(r'C:\Users\john\Desktop.pdf','rb')

}
That’s it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template