views:

50

answers:

1

I'm currently trying out websockets, creating a client in JavaScript and a server in Python.

I'm stuck on a simple problem, though: when I send something from the client to the server it always contains a special ending character, but I don't know how to remove it.

I've tried data[:-1] thinking that would get rid of it, but it didn't.

With the character my JSON code won't validate.

This is what I send through JavaScript:

 ws.send('{"test":"test"}');

This is what I get in python:

{"test":"test"}�

I thought the ending character was \xff

+1  A: 

The expression "data[:-1]" is an expression that produces a copy of data missing the last character. It doesn't modify the "data" variable. To do that, you have to assign back to "data", like so:

data = data[:-1]

My suspicion is the "special ending character" is a bug, somewhere, either in your code or how you're using the APIs. Network code does not generally introduce random characters into the data stream. Good luck!

Larry Hastings