chembl_webresource_client - RetryError Exception

This section provides a tutorial example to demonstrate a design issue in chembl_webresource_client, where the HTTP Status Code of '404 (Not Found)' is not handled properly.

chembl_webresource_client has a small design issue in its RetryError Exception. If you try to get a data entity with bad ID code, chembl_webresource_client will perform multiple retry requests, even the first request already returns a HTTP Status Code of "404 (Not Found)".

Below is a sample session that shows this problem:

herong$ python3

>>> from chembl_webresource_client.new_client import new_client
>>> molecule = new_client.molecule.get('JUNK')

Traceback (most recent call last):
  ...
  ".../python3.7/site-packages/urllib3/util/retry.py", line 574, in 
  increment raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.ebi.ac.uk',
  port=443): Max retries exceeded with url: /chembl/api/data/molecule/JUNK
  (Caused by ResponseError('too many 404 error responses'))

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  ...
  ".../python3.7/site-packages/requests/adapters.py", line 507, in send
    raise RetryError(e, request=request)
requests.exceptions.RetryError: HTTPSConnectionPool(host='www.ebi.ac.uk',
  port=443): Max retries exceeded with url: /chembl/api/data/molecule/JUNK
  (Caused by ResponseError('too many 404 error responses'))

If you run a HTTP request directly with the "curl" command, you will see the "HTTP/1.1 404 Not Found" message in the response header.

herong$ curl -D h.txt https://www.ebi.ac.uk/chembl/api/data/molecule/JUNK

herong$ more h.txt 

HTTP/1.1 404 Not Found
Server: gunicorn/20.0.4
Vary: Accept, Origin
Content-Type: text/html; charset=utf-8
Strict-Transport-Security: max-age=0
Connection: Keep-Alive
Content-Length: 0

A better design should stop the retry loop immediately and raise a new exception like "requests.exceptions.NotFoundError".

Table of Contents

 About This Book

 Introduction of Molecules

 Molecule Names and Identifications

 Molecule Mass and Weight

 Protein and Amino Acid

 Nucleobase, Nucleoside, Nucleotide, DNA and RNA

 Gene and Chromosome

 Protein Kinase (PK)

 DNA Sequencing

 Gene Mutation

 SDF (Structure Data File)

 PyMol Installation

 PyMol GUI and CLI

 PyMol Selections

 PyMol Editing Functions

 PyMol Measurement Functions

 PyMol Movie Functions

 PyMol Python Integration

 PyMol Object Functions

ChEMBL Database - European Molecular Biology Laboratory

 What Is ChEMBL

 ChEMBL Speical Web Portals

 Download ChEMBL Database

 ChEMBL FTP Repository

 ChEMBL Web Services API

 Call ChEMBL Data Web Service Directly

 ChEMBL Data Resource - molecule

 ChEMBL Data Resource - activity

 ChEMBL Data Resource - assay

 ChEMBL Data Resource - document

 ChEMBL Data Resource - target

 ChEMBL Data Resource - chembl_id_lookup

 ChEMBL Related Tools

 chembl_webresource_client - Python Client

 chembl_webresource_client - Usage Examples

chembl_webresource_client - RetryError Exception

 ChEMBL Terminologies

 PubChem Database - National Library of Medicine

 PDB (Protein Data Bank)

 INSDC (International Nucleotide Sequence Database Collaboration)

 HGNC (HUGO Gene Nomenclature Committee)

 Relocated Tutorials

 Resources and Tools

 Molecule Related Terminologies

 References

 Full Version in PDF/EPUB