Recently I created a bot for myself that captures data from a betting house and performs analyzes to help me with decisions, this bot was primarily running on my computer, but I needed it to be connected directly without stopping and I transferred it to a Raspberry Pi 3, I spent a few months this way and felt the need to put it on a VPS due to the fact that the internet is dedicated because at my house it sometimes crashed and caused an error in the bot. However, when I run the bot there the bookmaker blocks the connection, which is allowed on my machine, they block it and return:
Error: Server responded with a non-101 status: 403 Forbidden Response Headers Follow: date: Sun, 24 Mar 2024 18:22:59 GMT content-type: text/html; charset=UTF-8 content-length: 4515 connection: keep-alive x-frame-options: SAMEORIGIN referrer-policy: same-origin cache-control: max-age=15 expires: Sun, 24 Mar 2024 18:23:14 GMT server: cloudflare cf-ray: 8698b0956c492d9d-ORD
I don't understand much about networks so I have no idea why this happens, my bot is made in nodejs and the connection is via websocket.
My vps is an AWS EC2 virtual machine that uses Ubuntu.
To solve this, I tried to put the same parameters in the request header that are sent in the browser and it still didn't work.
const generateWebSocket = (func) => {
const client = new WebSocket({
headers: {
'Host': 'api-v2.******.space',
'Connection': 'Upgrade',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
'Accept-Language': 'pt-BR,pt;q=0.5',
'Upgrade': 'websocket',
'Origin': 'https://******.space',
'Sec-WebSocket-Version': '13',
'Accept-Encoding': 'gzip, deflate, br',
'Sec-WebSocket-Key': 'JjQKP7TvCpgscpTAv4Q4FA==',
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits'
}
});
let operator = 0;
client.on('connect', async (connection) => {
console.info('Conexão a ***** foi estabelecida.');
connection.send(msg1);
connection.send(msg2);
connection.on('message', func);
if (operator == 0){
operator ++;
scheduleNextMessage(connection);
scheduleNextMessageHour(connection);
}
});
return client
}