PubChemPy
PubChemPy copied to clipboard
BadRequestError
Running this code from the documentation:
pcp.get_compounds('CC', searchtype='superstructure', listkey_count=3)
Generates the following error:
Traceback (most recent call last): File "
", line 1, in File "c:\Python27\lib\site-packages\pubchempy.py", line 124, in get_compounds results = get_json(identifier, namespace, searchtype=searchtype, **kwargs) File "c:\Python27\lib\site-packages\pubchempy.py", line 109, in get_json return json.loads(get(identifier, namespace, domain, operation, 'JSON', sear chtype, **kwargs).decode()) File "c:\Python27\lib\site-packages\pubchempy.py", line 90, in get response = request(identifier, namespace, domain, None, 'JSON', searchtype, **kwargs).read() File "c:\Python27\lib\site-packages\pubchempy.py", line 84, in request raise PubChemHTTPError(e) File "c:\Python27\lib\site-packages\pubchempy.py", line 1089, in init raise BadRequestError(self.msg) pubchempy.BadRequestError: 'Bad Request'
This preceding example from the same page works without error:
>>> pcp.get_compounds('Aspirin', 'name', record_type='3d')
[Compound(2244)]
>>>
Having the same issue... Did you fix it?
same issue here
I think this is an error in the docs. The default identifier 'namespace' is CID, so if you want to query with SMILES you need to specify it with the second paramter:
>>> r = pcp.get_compounds('CC', 'smiles', searchtype='superstructure', listkey_count=3)
>>> print(r)
[Compound(6324), Compound(783), Compound(1038)]
Great, thanks for your work and your reply!
Hey @mcs07, really thanks for your work, I was looking for something which could give me the properties of the compounds using the SMILES notation. I tried using the get_properties function using the namespace as 'smiles' but I got the same error of BadRequestError. Is there any unique for every user through which we need to call the API to this library or what? I can't really understand as to why this error pops up, the procedure is pretty simple!! Please let me know if you could help me this query...
Regards Divyansh
sometimes props = pcp.get_properties([]) gives the results without much ado.Many times it fails to respond.
@DivyanshAgrawal22 Have you solved this problem?