我想使用ChemSpiPy使用here中记录的filter-name-post方法在ChemSpider数据库中搜索化合物,但是,我不确定应该在库的帖子中输入哪些参数功能。在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
答案 0 :(得分:0)
也许您正在寻找这个:
from chemspipy import ChemSpider
cs = ChemSpider("<API KEY>")
requestbody = {
"name": "carbon",
"orderBy": "",
"orderDirection": "",
}
print(cs.post('compounds', 'filter', 'name', requestbody))