PubChemPy icon indicating copy to clipboard operation
PubChemPy copied to clipboard

BadRequestError

Open kgChem opened this issue 7 years ago • 7 comments

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)]
>>>

kgChem avatar Jul 20 '18 19:07 kgChem

Having the same issue... Did you fix it?

wojiaodawei avatar Aug 14 '18 13:08 wojiaodawei

same issue here

codeprimate123 avatar Aug 28 '18 08:08 codeprimate123

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)]

mcs07 avatar Aug 29 '18 09:08 mcs07

Great, thanks for your work and your reply!

wojiaodawei avatar Aug 29 '18 12:08 wojiaodawei

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

DivyanshAgrawal22 avatar Nov 26 '20 07:11 DivyanshAgrawal22

sometimes props = pcp.get_properties([]) gives the results without much ado.Many times it fails to respond.

subramanianramajayam avatar Sep 07 '21 11:09 subramanianramajayam

@DivyanshAgrawal22 Have you solved this problem?

ZiyuFanCSU avatar Mar 08 '24 07:03 ZiyuFanCSU