记python爬虫坑2020年4月21日

python爬了小说更新的内容,转为本地txt文件,现需要通过一服务器API上传,但是多次提示: {"timestamp":"2020-04-20T17:21:01.457+0000","status":400,"error":"Bad Request","message":"Required request part 'file' is not present","path":"/upload"} 最后发现是由于我在headers中手动设置了Content-Type中的boundary的值和request请求时自动生成的请求表单中用来分隔不同参数的内容不一样。 Content-Type: multipart/form-data; boundary=9864967aa8b394b2f34e0b3a286c4118 这是我自己设置的⬆。 下图蓝色标注的的内容是不同点。 解决方案: 把headers中的 Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryu2c0iGeMDDxPB7dd 删掉,request请求时会自动生成。 参考资料: https://blog.csdn.net/five3/article/details/7181521 https://blog.csdn.net/Enderman_xiaohei/article/details/89421773

2021-05-20 18:37:46 更新