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
AttributeError: 'NoneType' object has no attribute 'throw_exception' #182
Comments
Just for the reference, I saw issue #76 and tried to reboot and to build package with zip_safe = False in setup.py, but to not avail. Anything I was able to google doesn't resolves the issue for me. |
Also tried to build package with replacing from setuptools import setup, Extension with from distutils.core import setup, Extension but still getting the same error upon importing. |
Ok, I was able to find the problem. The problem is in utils.py._find_libraries(). It doesn't using standard module imp or something and hardcodes the library path like that: So there is no way to work on ubuntu out of the box (w/o creating a symlink manually). May be it's better to switch to something more portable, like imp module: >>> import imp
>>> imp.find_module('libxtwrapper')[1]
'libxtwrapper.x86_64-linux-gnu.so' |
And here is a quick hack to make it working (for someone who may google this issue before the proper resolution found): --- util.py.orig 2016-06-28 12:04:37.000000000 +0300
+++ util.py 2016-06-28 14:13:36.000000000 +0300
@@ -79,8 +79,9 @@
ext = get_config_var("EXT_SUFFIX")
else:
ext = get_config_var('SO')
+ arch_ext = '.x86_64-linux-gnu'
for name in names:
- libnames = [name, "lib" + name, name + ext, "lib" + name + ext]
+ libnames = [name, "lib" + name, name + ext, "lib" + name + ext, "lib" + name + arch_ext + ext]
libdir = os.environ.get('IPTABLES_LIBDIR', None)
if libdir is not None:
libdirs = libdir.split(':') |
@mexicarne interesting. Can we leverage |
I believe yes, but can't come with exact patch at the moment. I just throw the idea :). Anyway, it's not your fault that debian/ubuntu changing the installed filename, and this is why the problem is not reproducible via pip/easy_install. But it would be great to support this as an exception for debian/ubuntu userbase. |
I just came across this issue running python 2.7.11 in RHEL 6.x (compiled my own). Downgrading to 0.10.0 worked. Only 0.11.0 has this issue. |
@lemsx1 can you post here the stack trace you get? |
|
@lemsx1 testing in a CentOS6.5, after manually installing Python 2.7.11 and pip installing python-iptables:
|
Hi @ldx - I'm in the process of packaging python-iptables for Debian and I'm running into the same bug when the .deb package is installed. Anything I can do to help? |
@FedericoCeratto can you tell me more about your environment? OS, iptables version, python version, python-iptables version? |
Hi @ldx - I have the same issue as the OP. My configuration: danc@dlserver ~/python-iptables $ sudo python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import iptc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "iptc/__init__.py", line 10, in <module>
from iptc.ip4tc import (is_table_available, Table, Chain, Rule, Match, Target,
File "iptc/ip4tc.py", line 13, in <module>
from .xtables import (XT_INV_PROTO, NFPROTO_IPV4, XTablesError, xtables,
File "iptc/xtables.py", line 709, in <module>
_throw = _lib_xtwrapper.throw_exception
AttributeError: 'NoneType' object has no attribute 'throw_exception'
>>> I'm happy to assist if you need anything further. |
@teracow can you try building and installing it? Python-iptables also include a C library that needs to be compiled.
should do the trick. |
Hi, I think I got past this error by copying libxtwrapper.so into /usr/lib/python2.7/dist-packages/ but this was some time ago, and I'm not 100% that that's all I did. I then switched projects and this kinda got dumped. If anyone had responded to my query at the time, I could have been more helpful. Sorry. |
Symlinking the shared obj to /usr/lib/python2.7/dist-packages/libxtwrapper.so helped but then the import fails like in #90 with:
|
@FedericoCeratto instead of symlinking, can you give a shot to the setup.py commands in my comment above? |
Would you please show the output of this command? I'm asking those who have this 'throw_exception' error.
Please post the output and your operating system info: name, version, architecture. |
I now think that it is not right to change find_library() or _find_library(), because these functions are looking for system libraries (libc etc), not only for libxtwrapper. So I come up with another solution to xtables.py that works for me and should be universal for any iptables-capable system. diff --git a/xtables.py.orig b/xtables.py
index 2cfccbb..0cf2493 100644
--- a/xtables.py.orig
+++ b/xtables.py
@@ -2,6 +2,7 @@
import ctypes as ct
import os
+import imp
import sys
import weakref
@@ -704,7 +705,7 @@ if _xtables_libdir is None:
raise XTablesError("can't find directory with extensions; "
"please set XTABLES_LIBDIR")
-_lib_xtwrapper, _ = find_library("xtwrapper")
+_lib_xtwrapper, _ = find_library(imp.find_module('libxtwrapper')[1])
_throw = _lib_xtwrapper.throw_exception Please let me know if it works for you. It works fine at Ubuntu 16.04 x64 |
@mexicarne works here. Can you open a PR? Thanks! |
Although the fix by @mexicarne seem to work on python 3.5 (though I don't have any problem even without this fix), it didn't solve the problem for 2.7:
|
@dadittoz please let us know what OS and which version you are using. How you installed iptc (package, pip) and what the full name of libxtwrapper.so in your system (should be somewhere in /usr/lib/python2.7/dist-packages). Thank you! |
Okay, I got it figured out. If I install python-iptables by adding to install_requires in my own project it doesn't work. But if I remove it and then use pip2 install python-iptables, it works fine. This is relevant to Python 2.7 only. Python 3.5 installation works fine either from install_requires or pip3 install. I really don't understand what black magic happens here. My OS is: Ubuntu 16.04.1 LTS x64 Let me know if you would like some install logs. I guess you can easily reproduce it by using python2, creating setup.py with
and then running
Produced installation will render the error as described above. |
Has anyone else been able to reproduce this problem on 16.04? |
I came here because I ran into the same problems as OP with a fresh cloned repo, but then I realized I had not installed the dependencies. I usually run python3 so I didn't have the module installed for python2, ergo the dependency was missing. I tried the following, to install my local version:
However, as @ldx indicated, I also tried buidling and installing with setup.py, but that didn't work:
By the way, installing via pip2 worked perfectly as well! A bit of info of my system
Let me know if I can help anyhow ;) |
Yeah, just checked this and I can confirm what @jllorente wrote above. The missing step is:
|
I think there is an underlying issue worth reopening because trying to
Same with |
it works for me |
Hello,
I'm trying to make python-iptables work on Ubuntu 16.04 x64. I did git clone from this repository, and built packages with dpkg-buildpackage using debian/ directory from repository. Then installed from created package. Getting this upon import iptc:
It looks like it's because libxtwrapper installed as /usr/lib/python2.7/dist-packages/libxtwrapper.x86_64-linux-gnu.so, not as /usr/lib/python2.7/dist-packages/libxtwrapper.so
If I create symlink or just copy this file to libxtwrapper.so, then all works fine. Can I do something about this? I need to propagate the package to a few servers, and I don't want to create symlinks everywhere manually.
Thank you.
The text was updated successfully, but these errors were encountered: