tamuctf / CTFd-multi-question-plugin

14 stars 10 forks source link

Cannot import name keys #3

Open wiperpaul opened 5 years ago

wiperpaul commented 5 years ago

Cant launch plugin due to following error.

ctfd_ctfd_1 exited with code 1 ctfd_1 | Traceback (most recent call last): ctfd_1 | File "manage.py", line 8, in <module> ctfd_1 | app = create_app() ctfd_1 | File "/opt/CTFd/CTFd/__init__.py", line 237, in create_app ctfd_1 | init_plugins(app) ctfd_1 | File "/opt/CTFd/CTFd/plugins/__init__.py", line 180, in init_plugins ctfd_1 | module = importlib.import_module(module, package="CTFd.plugins") ctfd_1 | File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module ctfd_1 | __import__(name) ctfd_1 | File "/opt/CTFd/CTFd/plugins/CTFd-multi-question-plugin/__init__.py", line 1, in <module> ctfd_1 | from CTFd.plugins import register_plugin_assets_directory, challenges, keys ctfd_1 | ImportError: cannot import name keys

NajibNour commented 5 years ago

Has a fix been found around this?

noraj commented 5 years ago

The plugin is not compatible with ctfd 2.1.4.

$ python serve.py
 * Loaded module, <module 'CTFd.plugins.challenges' from '/tmp/CTFd-2.1.4/CTFd/plugins/challenges/__init__.py'>
 * Loaded module, <module 'CTFd.plugins.dynamic_challenges' from '/tmp/CTFd-2.1.4/CTFd/plugins/dynamic_challenges/__init__.py'>
 * Loaded module, <module 'CTFd.plugins.flags' from '/tmp/CTFd-2.1.4/CTFd/plugins/flags/__init__.py'>
Traceback (most recent call last):
  File "serve.py", line 8, in <module>
    app = create_app()
  File "/tmp/CTFd-2.1.4/CTFd/__init__.py", line 237, in create_app
    init_plugins(app)
  File "/tmp/CTFd-2.1.4/CTFd/plugins/__init__.py", line 180, in init_plugins
    module = importlib.import_module(module, package="CTFd.plugins")
  File "/home/noraj/.pyenv/versions/3.7.2/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/tmp/CTFd-2.1.4/CTFd/plugins/multi-question/__init__.py", line 1, in <module>
    from CTFd.plugins import register_plugin_assets_directory, challenges, keys
ImportError: cannot import name 'keys' from 'CTFd.plugins' (/tmp/CTFd-2.1.4/CTFd/plugins/__init__.py)

See the documentation https://docs.ctfd.io/en/latest/plugins.html, mainly https://docs.ctfd.io/en/latest/plugins.html#challenge-types

Cause

keys was a plugin feature in CTFd 1.2.0

image

But it was removed in 2.0.0

image

So this plugin is not compatible with all CTFd 2.x.x

noraj commented 5 years ago

https://github.com/CTFd/CTFd/blob/master/CHANGELOG.md#200--2018-12-02

image

image

Th3l5D commented 5 years ago

Just FYI, I dug a bit and with some small modifications, the plugin is not throwing error. It does NOT mean that it is functionnal: once in the UI, there is some error when I try to load the MultiQuestion type of challenge, but I'm investigating.

Here is what I did to avoid python errors :

Change imports in __init__.py to this :

from CTFd.plugins.flags import get_flag_class
from CTFd.models import db, Solves, Fails, Flags, Challenges, Files, Tags, Teams
from CTFd import utils
from CTFd.utils.user import is_admin
from CTFd.utils.decorators import admins_only
import json
import datetime
from flask import jsonify, session, request
from flask_sqlalchemy import SQLAlchemy
import sys

Change any reference toget_key_class by get_flag_class

Change template extensions to .html instead of .njk (in files and in references in __init__.py)

alternox1 commented 1 year ago

Just FYI, I dug a bit and with some small modifications, the plugin is not throwing error. It does NOT mean that it is functionnal: once in the UI, there is some error when I try to load the MultiQuestion type of challenge, but I'm investigating.

Here is what I did to avoid python errors :

Change imports in init.py to this :

from CTFd.plugins.flags import get_flag_class
from CTFd.models import db, Solves, Fails, Flags, Challenges, Files, Tags, Teams
from CTFd import utils
from CTFd.utils.user import is_admin
from CTFd.utils.decorators import admins_only
import json
import datetime
from flask import jsonify, session, request
from flask_sqlalchemy import SQLAlchemy
import sys

Change any reference toget_key_class by get_flag_class

Change template extensions to .html instead of .njk (in files and in references in init.py)

did you find any solu ?