Answer the question
In order to leave comments, you need to log in
How to parse data generated by websocket?
Good afternoon, I ask for help in solving the problem.
There is a site, I would like to parse data from it, I go to it using base auth.
Inside the site there is data that is generated from the websocket. Parse using bs4 and so on does not work.
As I understand it, there is access to the socket and bypassing authorization, since if you go directly using the socket link,
there will be a message
Only WebSocket mode supported!
{"method":["RequestOpenStat"],"statname":["CurrMaxCallWaitingTime"],"objecttype":["queue"],"timeprofile":["Default"],"objectid":["[email protected]"],"filter":[""],"frq":["3"],"tenant":["Environment"],"tag":["105300001"]}
{"timestamp":["1557676913"],"referenceid":["22"],"interval_length":["4489244"],"tag":["105300000"],"string_value":["0"],"eventname":["EventInfo"]}
data_orig = {"method":["RequestOpenStat"],"statname":["CurrMaxCallWaitingTime"],"objecttype":["queue"],"timeprofile":["Default"],"objectid":["[email protected]"],"filter":[""],"frq":["3"],"tenant":["Environment"],"tag":["105300001"]}
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
def run(*args):
for i in range(3):
time.sleep(1)
ws.send(data_orig)
time.sleep(1)
ws.close()
print("thread terminating...")
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://*********",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
--- request header ---
GET /gvcc2/gadapter/ HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: ************
Origin: http://************
Sec-WebSocket-Key: 3dZ81p+lv47xnnEYGLBqPg==
Sec-WebSocket-Version: 13
-----------------------
--- response header ---
Handshake status 404 Not Found
### closed ###
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 981
Date: Sun, 12 May 2019 15:47:04 GMT
-----------------------
Answer the question
In order to leave comments, you need to log in
Well, first of all, the problem is related to the fact that the server web socket checks the origin of the client, and if the request comes from another domain, and even more so from another ip address, then the request is rejected.
It's possible to fake the origin header, but I don't know how legal that is.
https://blog.securityevaluators.com/websockets-not...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question