flask socketio 400 (BAD REQUEST)

See original GitHub issue

I’m trying to use flask socketio to retrieve some live tweets and currently I’m playing around with the socketio to see how it works. But in my test, I get 400 (BAD REQUEST) from time to time. I’m wondering what is the issue.

here’s the error sample:

socket.io.js:3511 POST http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=LOMYW0D&sid=c81baa220764437184a14366357c6d3d 400 (BAD REQUEST)Request.create @ socket.io.js:3511Request @ socket.io.js:3424XHR.request @ socket.io.js:3352XHR.doWrite @ socket.io.js:3365(anonymous function) @ socket.io.js:3884(anonymous function) @ socket.io.js:4747proxy @ socket.io.js:1197(anonymous function) @ socket.io.js:4762(anonymous function) @ socket.io.js:4742exports.encodePacket @ socket.io.js:4541encodeOne @ socket.io.js:4741eachWithIndex @ socket.io.js:4760map @ socket.io.js:4767exports.encodePayload @ socket.io.js:4746Polling.write @ socket.io.js:3883Transport.send @ socket.io.js:2912Socket.flush @ socket.io.js:2623Socket.sendPacket @ socket.io.js:2683Socket.ping @ socket.io.js:2587(anonymous function) @ socket.io.js:2574 socket.io.js:3511 GET http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=LOMYPYb&sid=c81baa220764437184a14366357c6d3d 400 (BAD REQUEST)Request.create @ socket.io.js:3511Request @ socket.io.js:3424XHR.request @ socket.io.js:3352XHR.doPoll @ socket.io.js:3382Polling.poll @ socket.io.js:3795Polling.onData @ socket.io.js:3834(anonymous function) @ socket.io.js:3385Emitter.emit @ socket.io.js:4389Request.onData @ socket.io.js:3546Request.onLoad @ socket.io.js:3627xhr.onreadystatechange @ socket.io.js:3499 socket.io.js:3511 POST http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=LOMYeOF&sid=c81baa220764437184a14366357c6d3d 400 (BAD REQUEST)

my server side code (python flask):

from flask import Flask
from flask_socketio import SocketIO
app = Flask(__name__)
app.config["SECRET_KEY"] = "secret!"
socketio = SocketIO(app)

def root():
    return app.send_static_file("index.html")

@socketio.on("connect", namespace="/npTweet")
def connectServer():
    print("Client connected")
    socketio.emit("connected", namespace="/npTweet")


@socketio.on("startTweets", namespace="/npTweet")
def tweetStreaming():
    print("Start streaming tweets...")
    socketio.emit("streamTweets", {"stream_result": "test"}, namespace="/npTweet")


if __name__ == "__main__":
    socketio.run(app, debug=True)

my client side code:

socket = io.connect("http://" + document.domain + ":" + location.port + "/npTweet");
console.log("http://" + document.domain + ":" + location.port + "/npTweet");
// listen to the event 'connected'
socket.on("connected", function(data){
  console.log("listening connected...");
  socket.emit("startTweets")
});

socket.on("streamTweets", function(data){
  console.log("listen streamTweets...");
  console.log(data.stream_result)
});

These are the initial output when I start the index.html page:

http://127.0.0.1:5000/npTweet
listening connected...
listen streamTweets...
test

but after like 30 second or so, it began to have the previous 400 bad request error, followed by the following result:

listening connected...
listen streamTweets...
test

Then after like 30 seconds, it does the bad request and the result all over again. where am I doing wrong? any help will be appreciated.

for the client side, I’m using socketio js 1.4.5 for python: Flask-SocketIO==2.5 python-engineio==0.9.2

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
BoYanSTKOcommented, Jul 23, 2016

what do you mean? can you point out where in the docs?

in my python code, I have:

if name == “main”: socketio.run(app, debug=True)

0reactions
miguelgrinbergcommented, Mar 28, 2019

@Alexcorrochano los errors 400 pueden ocurrir por muchas razones. Tendrias que averiguar cual es el problema en tu caso. Si activas los logs quiza sea mas claro.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flask-SocketIO and 400 Bad Request - python - Stack Overflow
The server's responding with a 400 Bad Request error because the request your frontend JavaScript code is sending isn't in the format the...
Read more >
Getting Started — Flask-SocketIO documentation
When the application is in debug mode the Werkzeug development server is still ... of connection problems, 400 responses, bad performance and other...
Read more >
Troubleshooting connection issues | Socket.IO
400 Bad Request : when something went wrong. In case of an HTTP 400 response, the response payload will be one of the...
Read more >
"Bad Request" when sending request to Socket.IO app via ...
The answer turned out to be very prosaic. As it turned out, the front-end had version 2 of Socket.IO , and on the...
Read more >
Socket.io call throwing 400 Bad Request for some users
Hi,We have hosted the Nodejs application using nginx as webserver with digicert ssl mapped to it. [label nginx.conf] user www-data; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found