python-3.x JSON为什么打不开?

pod7payv  于 2022-12-14  发布在  Python
关注(0)|答案(1)|浏览(181)

'

import requests

link = "https://developers.lingvolive.com/"

paramsGet = {'text': 'cat', 'srcLang': '1033', 'dstLang': '1049'}
headerGet = {'Authorization': 'Bearer ZXlKaGJHY2lPaUpJVXpJMU5pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SmxlSEFpT2pFMk56RXdNek14TURRc0lrMXZaR1ZzSWpwN0lrTm9ZWEpoWTNSbGNuTlFaWEpFWVhraU9qVXdNREF3TENKVmMyVnlTV1FpT2pjek1ERXNJbFZ1YVhGMVpVbGtJam9pT0RkaU1UazJNekF0TldNMFppMDBNREZqTFRrMk1EQXRObVk1Wm1JeFlqVXpObVkzSW4xOS5aekJvM3oyWmUycGRJVkRMbjE0ZFJIdlVaWEQybFhJLW9RTmFPanJneV9V'}

responseGet = requests.get(link, params=paramsGet, headers=headerGet)

print(responseGet.json())

'
以前从来没有这样做过,怎么落实?

omqzjyyz

omqzjyyz1#

在您当前的代码中,您没有尝试访问API;你只是在加载主网页。看起来你应该读一下api documentation available
对于您要尝试执行的操作,您似乎需要Translation API endpoint

import pprint
import requests

link = "https://developers.lingvolive.com/"

paramsGet = {'text': 'cat', 'srcLang': '1033', 'dstLang': '1049'}
headerGet = {'Authorization': 'Bearer ...'}

res = requests.get(f'{link}/api/v1/Translation', params=paramsGet, headers=headerGet)
res.raise_for_status()
print(res.text)

它产生大约40 KB的JSON输出,所以我不打算在这里包括它,但它是这样开始的:

[
  {
    "Title": "cat",
    "TitleMarkup": [
      {
        "IsItalics": false,
        "IsAccent": false,
        "Node": "Text",
        "Text": "cat",
        "IsOptional": false
      }
    ],
    "Dictionary": "LingvoUniversal (En-Ru)",
    "ArticleId": "LingvoUniversal (En-Ru)__cat",
    "Body": [

相关问题