TAXIIProject / django-taxii-services

Installable taxii_services
http://taxiiproject.github.io/
BSD 3-Clause "New" or "Revised" License
20 stars 13 forks source link

Error importing handler: taxii_services.PollRequestHandler #39

Open mgoffin opened 9 years ago

mgoffin commented 9 years ago

Getting the following response when attempting to poll using the latest version of Yeti (not sure if this belongs here or there):

Traceback: File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
  2. return view_func(_args, *_kwargs) File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/taxii_services-0.3-py2.7.egg/taxii_services/views.py" in service_router
  3. handler_class = getattr(module, class_name)

Exception Type: AttributeError at /services/poll/ Exception Value: (u'Error importing handler: taxii_services.PollRequestHandler', <type 'exceptions.AttributeError'>, AttributeError("'module' object has no attribute 'PollRequestHandler'",))

Sorry for the encoded stuffs, this is coming back as a Django error in the taxii_msg I get back. Latest master pull of Yeti.

MarkDavidson commented 9 years ago

@mgoffin,

Thank you for pointing this out. A recent commit by @gtback broke this (https://github.com/TAXIIProject/django-taxii-services/commit/d412c5af39efb7b71268b2a6add288f5b8f37784#diff-1db46ba9eb18f3e24afc09d5ef9247ea). I'll assign this issue to him for remediation.

-Mark

gtback commented 9 years ago

The commit I made was deliberate. I'm trying to get away from having import X import the entire library (for X in cybox, stix, maec, libtaxii, ...), which sometimes takes a few seconds and is inefficient for scripts called in a loop.

@mgoffin: You should be able to change to the following: from taxii_services.handlers.default import PollRequestHandler

@MarkDavidson If there's consensus to do it the other way, I can revert that commit.

mgoffin commented 9 years ago

@gtback That change would be in TAXII land, not the code I am writing. I can fix it locally but it would probably make more sense to fix it in taxii_services, yes?

MarkDavidson commented 9 years ago

@gtback

The use case is to be able to configure the model (from an admin page, not from code) in a succinct manner. Basically, the way it WAS organized, you'd have some form that's akin to:

Handler Name = MyCoolHandler
Handler = taxii_services.PollRequestHandler

If the path is longer, the form looks like:

Handler Name = MyCoolHandler
Handler = taxii_services.handlers.default.PollRequestHandler

My goal was to keep the Handler = ... part as small as possible. I don't know if I did that the best way (or if there's a way to keep the import lines working while also not making the import take too long).

So I think we're after two separate use cases. Mine is more of a user experience use case, I think, while yours is a code organization / code execution use case.

Thoughts?

Thank you. -Mark

gtback commented 9 years ago

@mgoffin: Sorry, I checked to see if it might be something in YETI, but didn't see "handler": "taxii_services.PollRequestHandler" in the initial_data.json, hence my (incorrect) assumption that it was in something you wrote. My preference would be to fix it in YETI.

@MarkDavidson: I've never liked exposing Python import paths to users, particularly in a web-based admin console (it's tolerable in a text config file, IMO). I understand why keeping them shorter is preferable, but if we decide to stick with that, I think we should catch the attribute error and raise a more sensible error (i.e. "Could not load Handler class taxii_services.PollRequestHandler for MyCoolHandler. Please check the Python path.")

gtback commented 9 years ago

@mgoffin : I released django-taxii-services 0.4 on PyPI, and updated YETI to include the new version in requirements.txt. Can you fetch the latest version of both projects and verify that this problem has been resolved?

mgoffin commented 9 years ago

Hoping I have some time today to test but if I don't I'll try to get to it as soon as possible!