【问题标题】:How to send .csv file using cURL in python如何在 python 中使用 cURL 发送 .csv 文件
【发布时间】:2021-12-26 00:32:43
【问题描述】:

我有 API,我需要在 python 中使用 cURL 发送一个 .csv 文件。我不知道如何在python上编写这个命令。

curl --location --request POST 'http://**************' \
--header 'Accept: application/json' \
--header 'API-AUTH-TOKEN: **************' \
--form 'list=@"/C:/Users/1288956/Downloads/ozon_search_query_test.csv"'
    • 表示无法显示

【问题讨论】:

标签: python api csv curl


【解决方案1】:

R.J. Adriaansen 给了我一个很好的答案:curlconverter.com

import requests

headers = {
    'Accept': 'application/json',
    'API-AUTH-TOKEN': '**************',
}

files = {
    'list': ('"/C:/Users/1288956/Downloads/ozon_search_query_test.csv"', open('"/C:/Users/1288956/Downloads/ozon_search_query_test.csv"', 'rb')),
}

response = requests.post('http:///**************', headers=headers, files=files)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 2020-02-20
    • 1970-01-01
    • 2021-12-24
    相关资源
    最近更新 更多