mychem.info icon indicating copy to clipboard operation
mychem.info copied to clipboard

Status code 400 (bad request) if more than 1000 IDs are posted to the chemical annotation service

Open erikyao opened this issue 3 years ago • 6 comments

API involved:

  • URL: http://mychem.info/v1/chem
  • HTTP method: POST

Per the document:

ids: Required. Accept multiple chemical ids separated by comma, e.g., “ids=SDUQYLNIPVEERB-QPPQHZFASA-N,SESFRYSPDFLNCH-UHFFFAOYSA-N,SHGAZHPCJJPHSC-ZVCIMWCZSA-N”. Note that currently we only take the input ids up to 1000 maximum, the rest will be omitted.

However if I have more than 1000 IDs, I'll receive a 400 bad request from server.

MWE:

import requests

drugbank_ids = [str(i) for i in range(1001)]  # 1001 fake IDs

url = 'http://mychem.info/v1/chem'
data = {"ids": ",".join(drugbank_ids)}
response = requests.post(url, data=data)

# raise an HTTPError if the HTTP request returned an unsuccessful status code 
response.raise_for_status()

# HTTPError: 400 Client Error: Bad Request for url: http://mychem.info/v1/chem

erikyao avatar Nov 05 '20 22:11 erikyao