Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

304
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda