@Nam Ly The above code seems to be keeping the connection open until the processing is done for all the images on the client side. Could you try to close the connection after the response from the API i.e after data = response.read().decode(encoding)
?
I think since the connection is open until all your images or items are processed on client side in the for loop the API is closing the connection after the default limit.
The initial response object should contain all the image details from the API, could you consider to print this response and check if the later processing is the issue?
Increasing the time out on your http.client call is an option but that can still keep the connection open for a long time until all images in the response object are processed.