小编Rui*_*ang的帖子

将curl转换为python请求

我正在尝试将以下curl请求转换为python请求(使用请求)

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "modelId=CommunitySentiment" -F "document=the presentation was great and I learned a lot"  https://api.einstein.ai/v2/language/sentiment
Run Code Online (Sandbox Code Playgroud)

响应将是一个 json {"probability": [{ "label": "positive", "probability": 0.8673582 }, { "label": "negative", "probability": 0.1316828 }, { "label": "中性”,“概率”:0.0009590242 } ] }

我的 python 脚本如下,但是,它返回 400 bad request。

import requests
import json

headers = {'Authorization': 'Bearer 1ca35fd8454f74ff5496614a858bfd4c80bd196b','Cache-Control': 'no-cache','Content-Type': 'multipart/form-data'}

files = json.dumps({'modelId':'CommunitySentiment','document': 'the presentation was great and I learned a lot'})

r = requests.post('https://api.einstein.ai/v2/language/sentiment', …
Run Code Online (Sandbox Code Playgroud)

python curl python-requests

4
推荐指数
1
解决办法
5601
查看次数

标签 统计

curl ×1

python ×1

python-requests ×1