miguelgrinberg / turbo-flask

Integration of Hotwire's Turbo library with Flask.
MIT License
301 stars 35 forks source link

Turbo-flask not able to push() on Raspberry Pi #29

Closed HFMan closed 2 years ago

HFMan commented 2 years ago

I can't get Push() to work when running the example demo on a Raspberry Pi (Debian Linux, stretch release). Python 3.8.13, Flask 2.0.3, Werkzeug 2.1.1.

turbo.can_push returns false when client is using Chrome or Edge. The same exact code running on Windows with same versions of Python, Flask, and Turbo-Flask works as expected (and identical Chrome and Edge clients).

Any idea what might be causing this?

miguelgrinberg commented 2 years ago

Are both tests establishing a websocket connection? That is probably what the difference is. If the test based on the RPi does not make a WebSocket connection, why is that? The client should have attempted a connection. Did it? If it did, why did it fail?

HFMan commented 2 years ago

Miguel,

I don't know exactly how to determine if a websocket connection has been made. No errors or any indication that a websocket connection failed was found in the server console output or anywhere else. Any suggestions on how to make this determination?

On Mon, Apr 11, 2022 at 4:59 PM Miguel Grinberg @.***> wrote:

Are both tests establishing a websocket connection? That is probably what the difference is. If the test based on the RPi does not make a WebSocket connection, why is that? The client should have attempted a connection. Did it? If it did, why did it fail?

— Reply to this email directly, view it on GitHub https://github.com/miguelgrinberg/turbo-flask/issues/29#issuecomment-1095671426, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNYRCQURGLLLLFLV2OMGVTVESVGXANCNFSM5TESM2LQ . You are receiving this because you authored the thread.Message ID: @.***>

HFMan commented 2 years ago

Okay- a bit more information. Using Chrome developer tools-> Network Tab, I have verified that the RPi does not make a WebSocket connection to my Chrome browser (but no errors indicated on the server side). I do see my HTML page in the client browser, but it does not dynamically update.

OTOH, running the same exact code on Windows Python, the same Chrome browser with developer tools enabled shows a WebSocket connection and it all works as expected.

Thoughts?

miguelgrinberg commented 2 years ago

that the RPi does not make a WebSocket connection to my Chrome browser

It's the reverse. The client makes the connection, not the server. Did the client attempt to connect? If it did, then you should see it in the network tab, maybe with an error response.

You may also want to look in the console section to see if there are any errors or interesting messages.

HFMan commented 2 years ago

Okay, now I understand. After you suggestion, via Chrome tools I determined that the rPi server was not serving up the script<> tag that defines the websocket that the client should be connecting to. So, that told me the Turbo object was not instantiating correctly. Alas- I discovered a small typo in my code where I instantiate the Turbo object, I had written {{ turbo }} as opposed to {{ turbo() }}. Small detail that was easy to miss, yet catastrophic. After fixing this, all is working properly. Thanks for your swift replies to this issue!

HFMan commented 2 years ago

User issue, not an issue with Turbo-flask