I'm trying to make a Python (3.9.2) client using requests
to communicate with a node.js (12.13.0) server using socket.io
over SSL.
It only works for me if I put verify = False
on Python client side. Without verify = False
I'm getting different errors, depends on the setup. What looks to me most valid throws the error from the header.
That setup is (simplified) -
Server Node.JS:
const express = require('express')
const fs = require('fs')
const socketIo = require("socket.io")
const app = express()
var cert = "path\to\cert.pfx"
if (fs.existsSync(cert)) {
httpsServer = require('https').createServer({
pfx: fs.readFileSync(cert),
passphrase: 'reall_pass_here',
requestCert: true,
rejectUnauthorized: false //shoud be true on production
}, app)
}
httpsServer.listen(port, function () {
console.log('[Info]', 'httpsServer is running on port', port);
});
app.post('/', async (req, res) => {
console.log(req.headers)
console.log(req.body)
//do nice things here
res.sendStatus(200)
})
Client Python:
import requests
response = requests.post("https://myserver.com:12457/"
# , verify = False
, headers={"Content-Type": "application/json"}
, data=json.dumps({"base64Image": encoded_string, "imageName": imageName}))
print("SendPhoto", response.status_code)
When using an online API tester service (like https://reqbin.com/) it works as expected, so I assume the issue is on the client side.
Looking here: https://stackoverflow.com/a/66111417/627100 and on similar posts, I can understand the problem is common, but the solution provided is not clear to me. As I have access to both server and client, I took the PEM certificate from the original GoDaddy files and paste it on the certifi PEM file on my client's venv. It didn't solve the problem. I'm certainly not sure if such act is even valid or secured. I also thought to export the certificate from the browser's padlock but it doesn't offer the PEM format. I understand that the server must serve the complete chain of certificates, including the intermediate ones. Maybe it doesn't (so how the online API tester works?) - how can I make it? or Make the client disregard the demand? or 'bring it' manually? (not valid for production...) I guess I need here a detailed explanation...