通过websocket python发送特殊字符时出错,问我?

时间:2019-12-22 05:33:11

标签: python python-3.x python-2.7 websocket

我想将数据发送到websocket服务器。

#!/usr/bin/env python
# -*- coding: utf-8 -*- 
import requests
import json
from websocket import create_connection

cookies = {
    '__cfduid': 'd3211d362d8d4927ee3f3e3b70d39a74f1576819006',
    '__cflb': '3244522586',
    'soisticky': 'http://10.0.3.159:80',
}

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0',
    'Accept': '*/*',
    'Accept-Language': 'th,en-US;q=0.7,en;q=0.3',
    'X-Requested-With': 'XMLHttpRequest',
    'Content-Type': 'text/plain;charset=UTF-8',
    'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjBERDlDRUYzQzVDMEE3REM2MzkxMzU0RDJGRUFFQzMwMjI5MUM5MEIiLCJ0eXAiOiJhdCtqd3QiLCJ4NXQiOiJEZG5PODhYQXA5eGprVFZOTC1yc01DS1J5UXMifQ.eyJuYmYiOjE1NzY4MTkwMTYsImV4cCI6MTU3NjgyMjYxNiwiaXNzIjoiaHR0cHM6Ly9vcGVuaWQuc29pY2hhdC5jb20iLCJhdWQiOiJhcGkxIiwiY2xpZW50X2lkIjoianMiLCJzdWIiOiI1OTgxMzAwIiwiYXV0aF90aW1lIjoxNTc2ODE5MDE2LCJpZHAiOiJsb2NhbCIsInNjb3BlIjpbInJvbGVzIiwicHJvZmlsZSIsIm9wZW5pZCIsImFwaTEiXSwiYW1yIjpbInB3ZCJdfQ.ezwB2eC4eMt9jvnZNl7r5whnSqma4FEnh7QGjRd1zTsZrg3rhNas7oENhXCefsAJyXeP9gRHVhxWmF-IcinpH2dQdxrdDGUWsUrJLCvB1ewNzSxbIz6jZhDBSyczE_PfkgMZl_r8FhoMgJOp2QIV_00Ee_WLtZDa312PRTfwwjBThJni0APB7JqpqxWccx_rQ1J853Eah7QTNLNVjQqSHbFieN8as6mXNSbsKSfFEZZ_PsA85V6qce1gipfNgrVFhTSomjG9XkWx2NxnWb9eyqck23nAj138Su4iJSgh0HhSpkl2t4KBi0poLsNpHwod8jK9B2KWQlp0Jy6Bgf66Xg',
    'Origin': 'https://v4.soichat.com',
    'DNT': '1',
    'Connection': 'keep-alive',
    'Referer': 'https://v4.soichat.com/board',
    'TE': 'Trailers',
}

response = requests.post('https://v4.soichat.com/hubs/soi/negotiate', headers=headers, cookies=cookies)
read = json.loads(response.text)

print read["connectionId"]

ws = create_connection("wss://v4.soichat.com/hubs/soi?id="+read["connectionId"]+"&access_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjBERDlDRUYzQzVDMEE3REM2MzkxMzU0RDJGRUFFQzMwMjI5MUM5MEIiLCJ0eXAiOiJhdCtqd3QiLCJ4NXQiOiJEZG5PODhYQXA5eGprVFZOTC1yc01DS1J5UXMifQ.eyJuYmYiOjE1NzY4MTkwMTYsImV4cCI6MTU3NjgyMjYxNiwiaXNzIjoiaHR0cHM6Ly9vcGVuaWQuc29pY2hhdC5jb20iLCJhdWQiOiJhcGkxIiwiY2xpZW50X2lkIjoianMiLCJzdWIiOiI1OTgxMzAwIiwiYXV0aF90aW1lIjoxNTc2ODE5MDE2LCJpZHAiOiJsb2NhbCIsInNjb3BlIjpbInJvbGVzIiwicHJvZmlsZSIsIm9wZW5pZCIsImFwaTEiXSwiYW1yIjpbInB3ZCJdfQ.ezwB2eC4eMt9jvnZNl7r5whnSqma4FEnh7QGjRd1zTsZrg3rhNas7oENhXCefsAJyXeP9gRHVhxWmF-IcinpH2dQdxrdDGUWsUrJLCvB1ewNzSxbIz6jZhDBSyczE_PfkgMZl_r8FhoMgJOp2QIV_00Ee_WLtZDa312PRTfwwjBThJni0APB7JqpqxWccx_rQ1J853Eah7QTNLNVjQqSHbFieN8as6mXNSbsKSfFEZZ_PsA85V6qce1gipfNgrVFhTSomjG9XkWx2NxnWb9eyqck23nAj138Su4iJSgh0HhSpkl2t4KBi0poLsNpHwod8jK9B2KWQlp0Jy6Bgf66Xg")
ws.send('{"arguments":[4992219,"asdfasdfasdf",1],"invocationId":"2","streamIds":[],"target":"postComment","type":1}')
result =  ws.recv()
print result
ws.close()

错误消息返回:“ error”:“连接握手期间发生意外错误。”

HERE

但是在burp套件中可以发送那些数据

IMAGE

在stackoverflow中,代码部分看不到特殊字符。请在这里查看。 IMAGE CODE

condition = df['sub_marks']>=df['total_marks']

print(condition)

1 个答案:

答案 0 :(得分:0)

首先,我将尝试发送一个更简单的ping像这样:

ws.send('ping')

看看会回来什么。如果可行,您的连接就在那里,但是您的框架不被接受