小编Luc*_*tto的帖子

如何向 deepL API 发出 python 请求?

我正在尝试制作一个 python 脚本来使用 DeepL API 进行翻译。我尝试发出请求,但它响应 HTTP 错误 400(错误请求)。

这是我的脚本代码,我用以下代码替换了真正的身份验证密钥XXX

import requests

url = "https://api.deepl.com"

auth_key = {
    'host' : "https://api.deepl.com/v2/translate?",
    'auth_key':"auth_key=XXX"
}

querystring = {
    "text" : "Che bellissima giornata",
    "target_lang" : "en"
}

response = requests.request("POST", url, headers=auth_key, data=querystring)

print(response)
print(response.text)
Run Code Online (Sandbox Code Playgroud)

python translation request deepl

6
推荐指数
2
解决办法
2935
查看次数

标签 统计

deepl ×1

python ×1

request ×1

translation ×1