python-3.x - 使用 cURL POST csv/文本文件

标签 python-3.x curl flask flask-restful

如何使用 cURL 将带有 csv 或文本文件的 POST 请求发送到在 localhost 上运行的服务器。

我尝试了 curl -X POST -d @file.csv http://localhost:5000/upload 但我得到了

{ "message": "The browser (or proxy) sent a request that this server could not understand." }

我的服务器是flask_restful API。预先非常感谢。

最佳答案

有许多替代方法可以实现此目的。一种方法是 我使用过以下内容:

curl -F ‘data=@<file_location>’ <URL>

例如。 curl -F data=@data.csv localhost:5000/h

你的命令也可以像这样稍微改变

curl -X POST -H 'Content-Type: text/csv' -d @file.csv http://localhost:5000/upload

以上是多种方式中的一种,可以作为表单或数据的一部分发送,也可以多部分发送等,可以引用Medium Post

关于python-3.x - 使用 cURL POST csv/文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50998620/

相关文章:

python-3.x - 这是如何在 Python 3 下使用 PyEphem 计算格林威治时角?

python-3.x - Python twint 库在 Colab 环境中无法运行

php - 如何获取链接标签的href内容

php - Curl 请求损坏 XML 发布数据

flask - 如何使用 flask app 中的 heroku 环境变量进行配置

python - Flask 单元测试抛出错误 : has no attribute 'csrf_token' in Jinja2 template

python - 找不到文件错误 : [WinError 2] The system cannot find the file specified:

python-3.x - 如何使用 gunicorn 运行 Flask 应用程序

php - 在 gearman 工作人员之间共享 curl 处理程序

python - 将 Flask 开发服务器配置为在整个网络中可见