Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python import error #172

Open
SuricataGuru opened this issue Nov 9, 2022 · 4 comments
Open

python import error #172

SuricataGuru opened this issue Nov 9, 2022 · 4 comments

Comments

@SuricataGuru
Copy link

I ran into an issue installing the server. There seems to be a python problem.

Command run:
python3 medallion/scripts/run.py --conf-file sample-config-with-memory-backend.json.

Error I saw after I ran the command:

Traceback (most recent call last):
File "medallion/scripts/run.py", line 10, in
from medallion.common import (
ImportError: cannot import name 'APPLICATION_INSTANCE'

Any idea on what is causing this error and how to fix it?

Thanks

@chisholm
Copy link
Contributor

How to reproduce this? I tried with a git clone of the master branch, using the config file in the test directory, and it worked:

>python .\medallion\scripts\run.py -c .\medallion\test\data\config.json
 * Serving Flask app 'medallion' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

I used python 3.9.13 on a win10 laptop.

@chisholm
Copy link
Contributor

Hah, just realized that config file was a sample that was in the repo! (I always use my own, and am aware of the unit tests and that data directory, and forgot those others were there.)

Ok, so it worked on master branch with sample-config-with-memory-backend.json as well:

>python .\medallion\scripts\run.py -c .\sample-config-with-memory-backend.json
 * Serving Flask app 'medallion' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

@SuricataGuru
Copy link
Author

SuricataGuru commented Nov 10, 2022

This may be an environmental issue, because I see you use a windows operating system.

For context, the exact steps I executed:

  1. Installed Centos7 on an ESXI vm
  2. Ran yum install git
  3. Ran git clone https://github.com/oasis-open/cti-taxii-server.git
  4. Ran cd cti-taxii-server
  5. Ran yum install python3 (which installed python 3.6.8)
  6. Ran python3 -m pip install --upgrade pip
  7. Ran python3 -m pip install medallion
  8. Ran python3 medallion/scripts/run.py --conf-file sample-config-with-memory-backend.json

@chisholm
Copy link
Contributor

I don't have access to a centos7 VM to accurately replicate your environment, but just from looking at the steps, I see some confusion. In step 7, you are installing medallion from pypi. In step 8, you are running medallion from your local git clone, which is a different codebase. You're mixing two different codebases: the git clone codebase and the pypi version. You need to decide which version you want to run.

If you want to use the version from your git clone directory, from within that directory run pip install . (or python3 -m pip ..., as you have done). That will cause pip to create an installable package from the sources and install it into your python environment (I don't see creation of a virtual environment in your list of steps, so I assume you can manage your environment).

If you want to use the version from pypi, all you need is to run pip install medallion. There is no need to git clone a repo; the installable package will be downloaded and installed automatically (though you will still need to get a config file from somewhere).

In either case, a medallion executable is created as part of the installation, so you can start medallion as medallion -c <config file>. If you have the python environment script directory in your $PATH, you should be able to run it. You don't need to use the run.py script directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants