Freeradius / python / 包导入失败

Freeradius / python / 包导入失败

我正在尝试将外部库导入(PyJWT)以进行 freeradius 授权,但是当我运行 freeradius -X 时出现此错误消息。

  # Instantiating module "python" from file /etc/freeradius/mods-enabled/python  
mod_init done
rlm_python:mod_load_function: module 'example' is not found  
rlm_python:EXCEPT:<type 'exceptions.ImportError'>: No module named jwt  
rlm_python:mod_load_function: failed to import python function 'example.authorize'  
/etc/freeradius/mods-enabled/python[10]: Instantiation failed for module "python"

当我尝试从终端导入包时,一切正常。

Python 2.7.10 (default, Oct 14 2015, 16:09:02)  
[GCC 5.2.1 20151010] on linux2  
Type "help", "copyright", "credits" or "license" for more information.  
>>> import jwt  
>>> encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')  
>>> jwt.decode(encoded, 'secret', algorithms=['HS256'])  
{u'some': u'payload'}  

该python文件是:

#! /usr/bin/env python  
# ...  

import radiusd  
import jwt   

def instantiate(p):  
 ....  
def authorize(p):  
  print "*** authorize ***"

但如果我使用:

#! /usr/bin/env python  
# ...  

import radiusd  
#import jwt   

def instantiate(p):  
 ....  
def authorize(p):  
  print "*** authorize ***"

,freeradius 按照预期开始。

我的docker文件是:

From ubuntu:15.10  

#1;5C radiussrvbase  docker image configuration file  
# This docker configuration file use ubuntu 15:10 willy distrib and   install freeradius server 3.x.  

RUN     apt-get update \  
        && apt-get install -y software-properties-common \  
        && apt-get install -y python2.7-dev \  
        && apt-get install -y python-pip \  
        && pip install PyJWT \  
        && add-apt-repository ppa:freeradius/stable-3.0 \  
        && apt-get update \  
        && apt-get install -y freeradius-mysql \  
        && apt-get install -y freeradius=3.0.11-ppa2~wily  

WORKDIR /etc/freeradius  
#File import

我应该在 freeradius 中声明外部 python 库吗?

我是否遗漏了什么?
谨致问候

答案1

你必须找到这个模块“jwt”在哪里,所以你把它包含在mods-available/python

python_path = ${modconfdir}/${.:name}:/path/to/the/package1:/path/to/the/package2

例子:

python_path = ${modconfdir}/${.:name}:/usr/lib/python2.7/

您可以通过以下方式查找:sudo find / -name "*jwt*"

相关内容