【问题标题】:How to use mashape with python request library?如何将 mashape 与 python 请求库一起使用?
【发布时间】:2023-03-23 08:23:02
【问题描述】:

Unirest 与 python3 不兼容,这是 mashape API 在 python 项目中使用的库。

我决定使用 python 请求库来发出 POST 请求,但我收到 400 HTTP 错误。一切对我来说都很好,但我不知道我做错了什么。

url = "https://japerk-text-processing.p.mashape.com/sentiment/"

myHeaders={
  "X-Mashape-Key": mashape_key,
  "Content-Type": "application/x-www-form-urlencoded",
  "Accept": "application/json"
}

myParams={
  "language": "english",
  "text": tweet_text
}

r = requests.post(url, headers=myHeaders, params=myParams)
print(r)

【问题讨论】:

    标签: python-3.x python-requests text-processing mashape


    【解决方案1】:

    根据the docs,UNIREST 接受参数:

    params - 请求正文作为关联数组或对象

    但是,根据 its own documentation,请求使用 params 提供 URL 查询参数,而不是请求正文。

    尝试使用data 参数来传递实际的请求正文;见the docs again。您可能必须反复检查两组文档中的参数名称,以确保您传递了正确的内容。

    【讨论】:

    猜你喜欢
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    • 2017-02-09
    相关资源
    最近更新 更多