需要帮助使用Python Library Chemspipy发布请求

问题描述 投票:0回答:1

我想使用ChemSpiPy在ChemSpider数据库中搜索一个化合物,使用filter-name-post方法记录here但是,我不确定我应该在库的post函数中输入什么参数。在documentation中,它表示参数应该如下:

post(api, namespace, endpoint, json=None)[source]

Convenience method for making POST requests.
Parameters: 

    api (string) – Top-level API, e.g. compounds.
    namespace (string) – API namespace, e.g. filter, lookups, records, or     tools.
    endpoint (string) – Web service endpoint URL.
    json (dict) – JSON data to send in the request body.

Returns:    

Web Service response content.
Return type:    

dict or string

我的代码目前看起来像这样:

from chemspipy import ChemSpider

cs = ChemSpider('<API KEY>')
compound_name = input('search for: ')
requestbody = {
    "name": compound_name,
    "orderBy": "",
    "orderDirection": ""
}
print(cs.post('compounds', 'filter-name-post', 'https://api.rsc.org/compounds/v1/filter/name', requestbody))

运行此代码并输入“carbon”之类的内容将返回以下内容:

Traceback (most recent call last):
  File "the path to my script", line 12, in <module>
    print(cs.post('filter', 'filter-name-post', 'https://api.rsc.org/compounds/v1/filter/name', requestbody))
  File "C:\python\lib\site-packages\chemspipy\api.py", line 181, in post
    return self.request('POST', api=api, namespace=namespace, endpoint=endpoint, json=json)  
  File "C:\python\lib\site-packages\chemspipy\api.py", line 154, in request
    raise err(message=r.reason, http_code=r.status_code)
chemspipy.errors.ChemSpiPyNotFoundError: Not Found
python python-3.x api soap
1个回答
0
投票

也许你正在寻找这个:

from chemspipy import ChemSpider
cs = ChemSpider("<API KEY>")

requestbody = {
    "name": "carbon",
    "orderBy": "",
    "orderDirection": "",
}

print(cs.post('compounds', 'filter', 'name', requestbody))
© www.soinside.com 2019 - 2024. All rights reserved.