0

I am trying to use django channels and asgi to run a simple chat server. I have channels and daphne installed, but when I try to run the development server, I get the following error.

Unhandled exception in thread started by <function wrapper at 0x1062fdc80>
Traceback (most recent call last):
  File "/Users/yash/code/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
     fn(*args, **kwargs)
  File "/Users/yash/code/lib/python2.7/site-packages/channels/management/commands/runserver.py", line 63, in inner_run
     "layer": self.channel_layer,
  File "/Users/yash/code/lib/python2.7/site-packages/channels/asgi.py", line 86, in __str__
      return "%s (%s)" % (self.alias, name_that_thing(self.channel_layer))
  File "/Users/yash/code/lib/python2.7/site-packages/channels/utils.py", line     25, in name_that_thing
      return name_that_thing(thing.__class__)
  File "/Users/yash/code/lib/python2.7/site-packages/channels/utils.py", line     16, in name_that_thing
      if hasattr(thing, "__class__") and not isinstance(thing, (types.FunctionType, types.MethodType)):
  AttributeError: 'module' object has no attribute 'FunctionType'

I have checked out the last file and found that the error is with the types module. the line import types worked fine, but when the script trys to call types.FunctionType it gives an AttributeError. When I imported the script on the shell, It worked as expected

Any help is greatly appreciated. :)

EDIT print(types) outputs: <module 'types' from '/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/types.pyc'>

EDIT 2 I started another django project with channels, cloned a repository from github. When I ran the development server after installing dependencies, It worked perfectly. The channels utils file is the exact same, so any help explaining this would help.

Superman
  • 196
  • 1
  • 2
  • 8
  • Can you do `print(types)` and show the result? – knbk Nov 27 '16 at 19:17
  • @knbk I posted the result – Superman Nov 28 '16 at 01:14
  • Possible duplicate of [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – pppery Aug 19 '19 at 13:50

1 Answers1

0

I was browsing other StackOverflow questions and I found a common bug in python scripts where a badly named file caused a import error. I looked around in the channel installation directory and found a file named types.py and changed this to typer.py and the program worked as normal. Thanks for the help.

Superman
  • 196
  • 1
  • 2
  • 8