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

[Android Termux]: _ffi ImportError: No module named _ffi #56

Open
realyukii opened this issue Oct 15, 2024 · 3 comments
Open

[Android Termux]: _ffi ImportError: No module named _ffi #56

realyukii opened this issue Oct 15, 2024 · 3 comments
Assignees

Comments

@realyukii
Copy link

I have encounter error that says: "_ffi ImportError: No module named _ffi" while run python script on Android 14 termux:

Package information:

(.venv) ~ $ pkg info libwolfssl
Package: libwolfssl
Version: 5.7.2
Maintainer: @termux
Installed-Size: 3891 kB
Homepage: https://www.wolfssl.com/
Download-Size: 630 kB
APT-Manual-Installed: yes
APT-Sources: https://mirrors.bfsu.edu.cn/termux/apt/termux-main stable/main aarch64 Packages
Description: A small, fast, portable implementation of TLS/SSL for embedded devices to the cloud

(.venv) ~ $ pip list
Package   Version
--------- -----------
cffi      1.17.1
pip       24.2
pycparser 2.22
wolfssl   5.7.2.post0
(.venv) ~ $

The code

(.venv) ~/d-net $ cat main.py
import socket
import wolfssl

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)

secure_socket = wolfssl.wrap_socket(sock)
secure_socket.connect(("dns.google.com", 443))
secure_socket.write(b"GET / HTTP/1.1\r\n\r\n")
print(secure_socket.read())
secure_socket.close()

(.venv) ~/d-net $

The error:

(.venv) ~ $ cd d-net/
(.venv) ~/d-net $ python main.py
Traceback (most recent call last):
  File "/data/data/com.termux/files/home/d-net/main.py", line 6, in <module>
    secure_socket = wolfssl.wrap_socket(sock)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 976, in wrap_socket
    return SSLSocket(sock=sock, keyfile=keyfile, certfile=certfile,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 407, in __init__
    self._context = SSLContext(ssl_version, server_side)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 144, in __init__
    _lib.wolfSSL_Init()
    ^^^^
NameError: name '_lib' is not defined
Exception ignored in: <function SSLContext.__del__ at 0x742a00c9a0>
Traceback (most recent call last):
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 167, in __del__
    if getattr(self, 'native_object', _ffi.NULL) != _ffi.NULL:
                                      ^^^^
NameError: name '_ffi' is not defined
Exception ignored in: <function SSLSocket.__del__ at 0x742a00d300>
Traceback (most recent call last):
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 469, in __del__
    self._release_native_object()
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 472, in _release_native_object
    if getattr(self, 'native_object', _ffi.NULL) != _ffi.NULL:
                                      ^^^^
NameError: name '_ffi' is not defined
(.venv) ~/d-net $

related link: wolfssl forum

@realyukii
Copy link
Author

Also happend inside the python interpreter:

(.venv) ~/d-net $ python
Python 3.12.7 (main, Oct  6 2024, 15:06:14) [Clang 18.0.2 (https://android.googlesource.com/toolchain/llvm-project d8003a456 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wolfssl
>>> import socket
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
>>> wolfssl.wrap_socket(sock)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 976, in wrap_socket
    return SSLSocket(sock=sock, keyfile=keyfile, certfile=certfile,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 407, in __init__
    self._context = SSLContext(ssl_version, server_side)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/home/d-net/.venv/lib/python3.12/site-packages/wolfssl/__init__.py", line 144, in __init__
    _lib.wolfSSL_Init()
    ^^^^
NameError: name '_lib' is not defined
>>>

@kareem-wolfssl kareem-wolfssl self-assigned this Oct 15, 2024
@lealem47
Copy link
Contributor

Hi @RealYukiSan,

I saw that you opened a different issue here #57 where it looks like you've gotten further along. Does that mean you have resolved this problem?

@realyukii
Copy link
Author

Not yet, the different issue run on my laptop.

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

3 participants