Устранение ошибки WebSocket 502 в коде PythonJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Устранение ошибки WebSocket 502 в коде Python

Сообщение Anonymous »

Я работаю над игрой под названием «Пиксели». Моя цель — программно отслеживать появление деревьев в игре. Разработчик предоставил мне для этого код Java, и я попытался преобразовать его в Python. Я могу успешно получить идентификатор своего сеанса, идентификатор комнаты и другие соответствующие сведения о сервере. Когда я пытаюсь установить соединение WebSocket, я постоянно получаю ошибку 502. Я не уверен, что является причиной этого.
public void openWebSocketAndProcessMessages(String server, String roomId, String sessionId) {
ReactorNettyWebSocketClient client = new ReactorNettyWebSocketClient();

client.setMaxFramePayloadLength(2621440);

URI uri = URI.create(

String.format("wss://pixels-server.pixels.xyz/%s/%s?sessionId=%s", server, roomId,

sessionId));

AtomicBoolean firstMessageReceived = new AtomicBoolean(false);

// Capture the start time of the session

Instant sessionStart = Instant.now();

client.execute(uri, session ->

session.receive()

.doOnNext(message -> {

// Check if the first message has been received and send a confirmation message

if (firstMessageReceived.compareAndSet(false, true)) {

System.out.println("First message received, sending confirmation...");

byte[] confirmationBytes = {'\n'}; // Newline character as the confirmation message

session.send(

Mono.just(session.binaryMessage(factory -> factory.wrap(confirmationBytes))))

.subscribe();

}

// Convert the received WebSocketMessage to a byte array (requires proper handling based on actual message type and content)

ByteBuffer buffer = message.getPayload().asByteBuffer();

byte[] messageBytes = new byte[buffer.remaining()];

buffer.get(messageBytes);

String encodedString = new String(Base64.getDecoder().decode(Base64.getEncoder().encodeToString(messageBytes)));


Websocket connection python code that I am getting 502 error:
'''

async def connect_websocket(server, roomid, sessionid):

uri = f"wss://pixels-server.pixels.xyz/{server}/{roomid}?sessionId={sessionid}"

print(uri)

headers = {

"Host": "pixels-server.pixels.xyz",

"Connection": "Upgrade",

"Upgrade": "websocket",

"Origin": "https://play.pixels.xyz",

"Sec-WebSocket-Version": "13",

"Sec-WebSocket-Key": "lAVNhobAP9AaShcdp/BegA==",

"Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits",

"User-Agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Mobile Safari/537.36",

"Pragma": "no-cache",

"Cache-Control": "no-cache",

"Accept-Encoding": "gzip, deflate, br, zstd",

"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",

"Cookie": "intercom-id-grzhbhyr=e4b3442d-7fbd-4660-b003-9796901fb523; intercom-device-id-grzhbhyr=48118693-0661-4e43-b3b9-e140ae8a692d; _ga=GA1.1.523002009.1710326782; _ga_QGP383C71B=GS1.1.1711873973.8.1.1711874126.0.0.0"

}

async with websockets.connect(uri, extra_headers=headers) as websocket:

while True:

message = await websocket.recv()

print(f"Received message: {message}
")'''

I'm unsure if there are any specific authentication requirements for the WebSocket connection that I might be missing.


Подробнее здесь: https://stackoverflow.com/questions/782 ... ython-code
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»