没有JSON对象可以被Python解码

2024-09-30 12:16:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从这个website获取一些数据。我可以输入'text'和'longest'only'参数,但是当我传递'ontologys'参数时,它说没有JSON对象可以解码。这是完整的URL

^{pr1}$ 我使用的是python2.7

Tags: 数据对象textjsonurlonly参数longest
2条回答

参数是ontologies[],因为您可以指定多个参数。您的请求应该与online search使用的请求类似:

text=lung+cancer%2Cbone+marrow&ontologies%5B%5D=NCIT&longest_only=true&raw=true

只需在那里执行相同的搜索,并使用您喜爱的浏览器的developer tools选项来检查实际发送的有效负载是什么。在

这不是一个答案,但我可以显示在执行示例代码时看到的错误的唯一位置。我将代码放在main中的一个新模块中,并在Python3.4中运行它。在

import requests

if __name__ == '__main__':
    url = 'http://bioportal.bioontology.org/annotator'
    params = {
        'text': 'lung cancer,bone marrow',
        'ontologies': 'NCIT',
        'longest_only': 'true'
    }

    session = requests.Session()
    session.get(url)

    response = session.post(url, data=params)
    data = response.json()

    # get the annotations
    for annotation in data['annotations']:
        print (annotation['annotatedClass']['prefLabel'])

我收到以下错误。在

^{pr2}$

相关问题 更多 >

    热门问题