Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
How identify if websocket client connection from of browser or python?

I was connecting to a websocket a website to collect data from python module websockets but it stopped working for some unknown reason for now. But I noticed that if I connect through the browser with javascript, regardless of the website I connect to, the data comes to me, whether cookies are disabled or not. I would like to know if there is any way to identify if the connection is through the browser, or some other way, so that I can try to work around this.

successful connecting by javascript in any website:

const ws = new WebSocket("wss://premws-pt1.365lpodds.com/zap", "zap-protocol-v1");
 
ws.addEventListener('open', (e) => {
  console.log("connected")
})

ws.addEventListener('message', (message) => {
  console.log(message.data)
})

ws.addEventListener('error', (error) => {
  console.log(error)
})

output: connected

unsuccessful connection by python using websockets package:

import asyncio
import websockets

headers = {
  'Pragma': 'no-cache',
  'Accept-Language': 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36',
  'Upgrade': 'websocket',
  'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
  'Cache-Control': 'no-cache',
  'Connection': 'Upgrade',
  'Sec-WebSocket-Version': '13',
}
 
async def main():
  try:
    async with websockets.connect('wss://premws-pt1.365lpodds.com/zap/', extra_headers=headers, origin="https://www.bet365.com", subprotocols=['zap-protocol-v1']) as websocket:
      print("connected")
  except websockets.exceptions.InvalidStatusCode as e:     
    print(e)
 
asyncio.get_event_loop().run_until_complete(main())

output: server rejected WebSocket connection: HTTP 403

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda