django-socketio icon indicating copy to clipboard operation
django-socketio copied to clipboard

Error installing

Open esarearthur opened this issue 7 years ago • 17 comments

I keep getting this error when I install.

Collecting django-socketio==0.3.9 Using cached django-socketio-0.3.9.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "C:\Users\esare\AppData\Local\Temp\pip-build-qa39znes\django-socketio\setup.py", line 7, in version = import("django_socketio").version, File "C:\Users\esare\AppData\Local\Temp\pip-build-qa39znes\django-socketio\django_socketio_init_.py", line 2, in from django_socketio.utils import NoSocket, send, broadcast, broadcast_channel File "C:\Users\esare\AppData\Local\Temp\pip-build-qa39znes\django-socketio\django_socketio\utils.py", line 44 except IndexError, KeyError: ^ SyntaxError: invalid syntax

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\esare\AppData\Local\Temp\pip-build-qa39znes\django-socketio\

esarearthur avatar Jun 30 '17 08:06 esarearthur

Cloned and installed it manually it is working fine

esarearthur avatar Jun 30 '17 08:06 esarearthur

the same error(

andriy-sa avatar Jul 05 '17 08:07 andriy-sa

maybe pip3 install django_socketio can solve

Chunmi-Tommy3886 avatar Aug 02 '17 05:08 Chunmi-Tommy3886

Hello there support team, I got the same error while installing it. I also tried installing it manually but still nothing. I'm using django version 2.0. Please help.

adnanrafique avatar Aug 30 '18 13:08 adnanrafique

same error

nh916 avatar May 19 '19 06:05 nh916

same error

dashko avatar Mar 24 '20 07:03 dashko

same error !

dushanchen avatar Mar 30 '20 06:03 dushanchen

python3.7 , django2.1.4, pip3 install django_socketio and python3 setup.py install, both got this:

except IndexError, KeyError: ^ SyntaxError: invalid syntax ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

dushanchen avatar Mar 30 '20 06:03 dushanchen

I had the same problem too, but I found that while pip install django-socketio returns an error, pip install -U django-socketio works seamlessly.

avidcoder123 avatar Sep 15 '20 18:09 avidcoder123

same issue

nalibjchn avatar Oct 21 '20 21:10 nalibjchn

I used python 2.7, it works. you have to degrade your python version.

nalibjchn avatar Oct 21 '20 21:10 nalibjchn

@lindalibjchn I think Python 2 is going out of style and will have less support so its not an option.

but now that we know that it works with python 2 and not 3, maybe we can just update it from python 2 to python 3 and itll work again

nh916 avatar Oct 22 '20 02:10 nh916

The latest version of django-socketio is released on 2014. It's seems pretty old. I think it's better to use Django Channels.

For references, Check documentation

Muhammed-Rajab avatar May 02 '21 01:05 Muhammed-Rajab

I used python 2.7, it works. you have to degrade your python version.

It's not a great idea to degrade to 2.7. It's pretty old and not recommended..

Muhammed-Rajab avatar May 02 '21 01:05 Muhammed-Rajab

pip install django-socketio problem

Collecting django-socketio Downloading django-socketio-0.3.9.tar.gz (48 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.0/48.0 kB 401.8 kB/s eta 0:00:00 Preparing metadata (setup.py) ... error error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [11 lines of output] Traceback (most recent call last): File "", line 2, in File "", line 34, in File "C:\Users\dell 5470\AppData\Local\Temp\pip-install-63_gzqda\django-socketio_6ddb8fd399e44adb9a9f6512d320f464\setup.py", line 7, in version = import("django_socketio").version, File "C:\Users\dell 5470\AppData\Local\Temp\pip-install-63_gzqda\django-socketio_6ddb8fd399e44adb9a9f6512d320f464\django_socketio_init_.py", line 2, in from django_socketio.utils import NoSocket, send, broadcast, broadcast_channel File "C:\Users\dell 5470\AppData\Local\Temp\pip-install-63_gzqda\django-socketio_6ddb8fd399e44adb9a9f6512d320f464\django_socketio\utils.py", line 44
except IndexError, KeyError: ^^^^^^^^^^^^^^^^^^^^ SyntaxError: multiple exception types must be parenthesized [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed

× Encountered error while generating package metadata. ╰─> See above for output.

note: This is an issue with the package mentioned above, not pip. hint: See above for details.

Jaykumar-Maradiya avatar Aug 23 '23 05:08 Jaykumar-Maradiya

I have solutions for this installation problem

  1. Add manually in your site-packages (https://www.youtube.com/watch?v=DKR0VYSOqLc&ab_channel=ProgrammingwithMosh)

  2. If you are using python 3.10 version python 3.10 does not support some methods inside this django-socketio so replace this package .

  3. Name the file events.py Replace your code with my code import re class EventError(Exception): pass class Event(object): """ Signal-like object for Socket.IO events that supports filtering on channels. Registering event handlers is performed by using the Event instance as a decorator::

     @on_message
     def message(request, socket, message):
         ...
    

    Event handlers can also be registered for particular channels using the channel keyword argument with a regular expression pattern::

     @on_message(channel="^room-")
     def message(request, socket, message):
         ...
    

    The on_connect event cannot be registered with a channel pattern since channel subscription occurs after a connection is established. """

    def init(self, supports_channels=True): self.supports_channels = supports_channels self.handlers = []

    def call(self, handler=None, channel=None): """ Decorates the given handler. The event may be called with only a channel argument, in which case return a decorator with the channel argument bound. """ if handler is None: def handler_with_channel(handler): return self.call(handler, channel)

         return handler_with_channel
     if channel:
         if not self.supports_channels:
             raise EventError("The %s event does not support channels so "
                              "the handler `%s` could not be registered" %
                              (self.name, handler.__name__))
         channel = re.compile(channel)
     self.handlers.append((handler, channel))
    

    def send(self, request, socket, context, *args): """ When an event is sent, run all relevant handlers. Relevant handlers are those without a channel pattern when the given socket is not subscribed to any particular channel, or the handlers with a channel pattern that matches any of the channels that the given socket is subscribed to.

     In the case of subscribe/unsubscribe, match the channel arg
     being sent to the channel pattern.
     """
     for handler, pattern in self.handlers:
         no_channel = not pattern and not socket.channels
         if self.name.endswith("subscribe") and pattern:
             matches = [pattern.match(args[0])]
         else:
             matches = [pattern.match(c) for c in socket.channels if pattern]
         if no_channel or any(filter(None, matches)):
             handler(request, socket, context, *args)
    

Define a list to hold Event instances

event_instances = []

on_connect = Event(False) on_message = Event() on_subscribe = Event() on_unsubscribe = Event() on_error = Event() on_disconnect = Event() on_finish = Event()

Add the Event instances to the list

event_instances.extend([ on_connect, on_message, on_subscribe, on_unsubscribe, on_error, on_disconnect, on_finish ])

Set the "name" attribute for each Event instance

for event_instance in event_instances: setattr(event_instance, "name", event_instance)

Now you can continue using the Event instances as before

  1. Name the file utils.py Replace your code with my code except (IndexError, KeyError):

I hope django-scoketio will work after all these changes

Jaykumar-Maradiya avatar Aug 23 '23 06:08 Jaykumar-Maradiya

events.py file


**import re


class EventError(Exception):
    pass


class Event(object):
    """
    Signal-like object for Socket.IO events that supports
    filtering on channels. Registering event handlers is
    performed by using the Event instance as a decorator::

        @on_message
        def message(request, socket, message):
            ...

    Event handlers can also be registered for particular
    channels using the channel keyword argument with a
    regular expression pattern::

        @on_message(channel="^room-")
        def message(request, socket, message):
            ...

    The ``on_connect`` event cannot be registered with a
    channel pattern since channel subscription occurs
    after a connection is established.
    """

    def __init__(self, supports_channels=True):
        self.supports_channels = supports_channels
        self.handlers = []

    def __call__(self, handler=None, channel=None):
        """
        Decorates the given handler. The event may be called
        with only a channel argument, in which case return a
        decorator with the channel argument bound.
        """
        if handler is None:
            def handler_with_channel(handler):
                return self.__call__(handler, channel)

            return handler_with_channel
        if channel:
            if not self.supports_channels:
                raise EventError("The %s event does not support channels so "
                                 "the handler `%s` could not be registered" %
                                 (self.name, handler.__name__))
            channel = re.compile(channel)
        self.handlers.append((handler, channel))

    def send(self, request, socket, context, *args):
        """
        When an event is sent, run all relevant handlers. Relevant
        handlers are those without a channel pattern when the given
        socket is not subscribed to any particular channel, or the
        handlers with a channel pattern that matches any of the
        channels that the given socket is subscribed to.

        In the case of subscribe/unsubscribe, match the channel arg
        being sent to the channel pattern.
        """
        for handler, pattern in self.handlers:
            no_channel = not pattern and not socket.channels
            if self.name.endswith("subscribe") and pattern:
                matches = [pattern.match(args[0])]
            else:
                matches = [pattern.match(c) for c in socket.channels if pattern]
            if no_channel or any(filter(None, matches)):
                handler(request, socket, context, *args)


# Define a list to hold Event instances
event_instances = []

on_connect = Event(False)
on_message = Event()
on_subscribe = Event()
on_unsubscribe = Event()
on_error = Event()
on_disconnect = Event()
on_finish = Event()

# Add the Event instances to the list
event_instances.extend([
    on_connect,
    on_message,
    on_subscribe,
    on_unsubscribe,
    on_error,
    on_disconnect,
    on_finish
])

# Set the "name" attribute for each Event instance
for event_instance in event_instances:
    setattr(event_instance, "name", event_instance)

# Now you can continue using the Event instances as before**

utils.py

except (IndexError, KeyError):

Jaykumar-Maradiya avatar Aug 23 '23 07:08 Jaykumar-Maradiya