通过websocket python发送特殊字符时出错 Hele me?
Posted
技术标签:
【中文标题】通过websocket python发送特殊字符时出错 Hele me?【英文标题】:Error when sending special characters via websocket python Hele me? 【发布时间】:2019-12-22 05:33:11 【问题描述】:我想将数据发送到 websocket 服务器。
"arguments":[4992219,"asdfasdfasdf",1],"invocationId":"2","streamIds":[],"target":"postComment","type":1
错误消息返回:“错误”:“连接握手期间发生意外错误。”
HERE
但在 burp 套件中可以发送那些数据
IMAGE 在 *** 代码部分看不到特殊字符。请在这里查看。 IMAGECODE
#!/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()
【问题讨论】:
始终将代码、数据和错误消息显示为文本,而不是图像。我在您的文字中没有看到任何特殊字符。 @furas in url uppic.cc/d/5CrL 您的错误可能意味着连接问题 - 在您尝试发送特殊字符之前。您可以在代码行之间添加一些print()
,以查看您在哪个时刻出现错误。
@furas 我在发送数据之前尝试连接。可以正常连接
@furas 我尝试发送没有特殊字符的信息,发现可以正常发送。
【参考方案1】:
首先我会尝试发送一个更简单的 ping,例如:
ws.send('ping')
看看会发生什么。如果这可行,您的连接就在那里,但您的框架不被接受
【讨论】:
以上是关于通过websocket python发送特殊字符时出错 Hele me?的主要内容,如果未能解决你的问题,请参考以下文章
在使用 websockets 时,我可以在发送查询字符串时传入标头吗?
是否可以通过 126 个字符发送 websocket 数据?