mcs07 / PubChemPy

Python wrapper for the PubChem PUG REST API.
http://pubchempy.readthedocs.io
MIT License
386 stars 108 forks source link

BadRequestError #33

Open kgChem opened 6 years ago

kgChem commented 6 years ago

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)]
>>>
wojiaodawei commented 6 years ago

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

codeprimate123 commented 6 years ago

same issue here

mcs07 commented 6 years ago

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)]
wojiaodawei commented 6 years ago

Great, thanks for your work and your reply!

DivyanshAgrawal22 commented 3 years ago

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

subramanianramajayam commented 3 years ago

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

ZiyuFanCSU commented 7 months ago

@DivyanshAgrawal22 Have you solved this problem?