event-source-library icon indicating copy to clipboard operation
event-source-library copied to clipboard

confusing error on port mismatch

Open ghost opened this issue 9 years ago • 3 comments

  • install event-source-library via pip install
  • run server on non-defaul port: eventsource-server -P 8888 -i -k 50000
  • try to tun client on default port: eventsource-client 42:42:42:42:42:42 -r 5000 - it will terminate with following error:
Traceback (most recent call last):
  File "/home/msuraev/.local/lib/python2.7/site-packages/eventsource/client.py", line 139, in handle_stream
    (field, value) = line.split(":", 1)
ValueError: need more than 1 value to unpack
ERROR:eventsource.client:HTTP 599: Failed writing body (0 != 877)

Hmm, looking further into this, seems like it's not the port to be blamed - I've got the same error if I run eventsource-server -i -k 50000 instead.

Note, that running both client and the server with -P 8888 fixes it. What's the default port used if -P not specified? In general, I think every option with default value should explicitly mention that value in '--help' output to make troubleshooting easier.

Incidentally, trying to connect with some "empty" port leads to expected error:

eventsource-client 42:42:42:42:42:42 -r 5000 -P 1111 

ERROR:eventsource.client:HTTP 599: Failed to connect to 127.0.0.1 port 1111: Connection refused

So it seems like eventsource-client got confused by smth else running on the default port but I don't understand how it's possible - if the port is already occupied than eventsource-server would have complained about it?

ghost avatar Aug 01 '16 10:08 ghost

I'm sorry but I cannot replicate with latest from the repository I'm getting:

ERROR:eventsource.client:HTTP 599: Failed to connect to 127.0.0.1 port 80: Connection refused

which by the way, shows that the default port is 80. You're right defaults should be in --help and sorry that argparse does not handles that directly (on all my newer projects, I'm using docopt which makes more comprehensive and better --help messages).

Maybe the issue could be that you've got a webserver running on port 80, and it connects to it, and gives back something it does not understand, like a 404 message. That would be a case worth checking against, and we could add a proper error there.

guyzmo avatar Aug 01 '16 14:08 guyzmo

Yepp, that's the case - smth else is running on that port and gives confusing result. The bigger question is how come "eventsource-server" successfully binds to an already occupied port?

ghost avatar Aug 08 '16 09:08 ghost

Hum… it's most likely it does not and fails to report the issue. Would be worth investigating.

guyzmo avatar Aug 08 '16 15:08 guyzmo