python - 如何在烧瓶 python 应用程序中执行 curl POST 命令
问题描述
我在一个小烧瓶应用程序上工作,该应用程序包括使用关键字(ElasticSSearch)搜索文档并在集群中上传文档。
搜索文档工作正常,但上传很难,我可以用 curl 做,但我有一些问题
我的 curl 命令是这样的:
curl -F "file=@pdf-test.pdf" "http://127.0.0.1:pdf-8080/fscrawler/_upload"
我的html是:
<form id="uploadbanner" enctype="multipart/form-data" method="post" action="/">
<input id="fileupload" name="myfile" type="file" />
<input type="submit" value="submit" id="submit" />
</form>
为了为客户端创建上传按钮。
我看到了很多关于请求库的话题,但是我的 py 代码不起作用,我真的不明白我做错了什么,我很迷茫。
我给你我试过的:
def upload():
url="http://127.0.0.1:8080/fscrawler/_upload"
if request.method == 'POST':
payload = open("test.pdf")
r = requests.post(url, data=payload)
感谢您的帮助,祝您有美好的一天:)
解决方案
Try:
curl -F "myfile=@pdf-test.pdf" "http://127.0.0.1:pdf-8080/fscrawler/_upload"
The name of your file input needs to be the same in curl and html.
推荐阅读
- vba - 如何在跟踪单个单元格的更改时允许多个单元格选择
- swift - 如何使用 swift 在 Heroku 应用上上传图片
- java - 如何在我的 ButtonActionPerformed 中调用此方法
- c# - 折线仅绘制 2 条线和 Point.Parse 问题
- php - 验证请求视频文件 (Laravel)
- r - 将一个数据帧中的单元格值与另一数据帧中的相应单元格值连接起来
- javascript - 如果 id 与值在同一个数组中,如何在 JSON 块中找到值?
- django - React Redux 简单的 GET Api 调用
- postgresql - Postgres 执行计划图片
- android - 向数据库中插入数据时如何将数据插入到表的前面?