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)