1

I am writing a little REST API client using Python, Java and NodeJS. The server is written using the Mongoose HTTP server.

With Java and NodeJS every request takes only milliseconds but with Python every request takes 2 seonds.

I confirmed that this is not a requests problem by using urllib directly. This also takes 2 seconds per request.

I also tried "Connection" "Close", no change...

Any ideas why the request takes 2 seconds with Python but not with Java and NodeJS ?

My code:

import json
from urllib import request
from datetime import datetime

url = "http://localhost:8080/api"

req = request.Request(url, method="POST")
req.add_header('Content-Type', 'application/json')
req.add_header("Connection", "Close")

myData = {
            "schema": "jsonCommand.org/v1",
            "requestId": 1,
            "api": "admin",
            "apiVersion": "1.0",
            "action": "pingSession"
        }

data = json.dumps(myData)
data = data.encode()

for i in range(0, 10):
    now = datetime.now()
    print('Current DateTime:', now)
    with request.urlopen(req, data=data) as response:
        body = response.read()
        print(body)
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53

1 Answers1

0

Most probably you're not using mg_http_reply() API. Solution: use it. Reason: your server does not set content length, and/or end-of-response marker. See https://mongoose.ws/tutorials/http-server/#set-content-length details.

valenok
  • 827
  • 7
  • 9