1

I have a local REST API server that returns some data after querying the database. The API takes DateTime as parameters(to & from). I use a python script to call this API. Every time I call this API for the time range 2021-07-03T04:00:00.000Z & 2021-07-03T16:00:00.000Z, I get ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) error.

I have checked the log, the API returns the data successfully. The API takes about 2-3 minutes to return this data. Please find my python script below:

Solutions that I tried:

  1. I have tried out this solution(Not accepted solution though): https://stackoverflow.com/a/36783679
time.sleep(1)
MAX_RETRIES = 20
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(max_retries=MAX_RETRIES)
session.mount('https://', adapter)
session.mount('http://', adapter)
session = requests.Session()
response = session.get(endpoint, timeout=500)
  1. https://stackoverflow.com/a/55029661

Added header as mentioned in the above link.

endpoint = 'http://localhost:8080/v1/metrics/report?from=' + from_date + 'T' + from_time + '.000Z&to=' + to_date + 'T' + to_time + '.000Z&franchise=' + res + '&timezone=cst'
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                  "Chrome/72.0.3626.119 Safari/537.36"}
resp = requests.get(endpoint, timeout=5000, headers=headers)

resp_data = resp.json()
  1. Also tried the combination of these two
endpoint = 'http://localhost:8080/v1/metrics/report?from=' + from_date + 'T' + from_time + '.000Z&to=' + to_date + 'T' + to_time + '.000Z&franchise=' + res + '&timezone=cst'
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                  "Chrome/72.0.3626.119 Safari/537.36"}
sess = requests.Session()
resp = sess.get(endpoint, timeout=5000, headers=headers)

resp_data = resp.json()

I could not figure out the issue with the python script.

theone1one
  • 1,510
  • 3
  • 20
  • 27

0 Answers0