I have a Python script that I try to run from Openresty/Lua with the following Nginx location block:
location / {
access_by_lua_block {
ngx.req.read_body()
local request = ngx.req.get_body_data()
io.popen("python3 /www/test.py '" .. request .. "'")
}
}
Script content:
#!/usr/bin/python3
import sys
import json
(...)
-- Run from command line => works
-- Run from Lua => works
But if I try to import mysql.connector it no longer works from Lua, although it still does from the command line:
#!/usr/bin/python3
import sys
import json
import mysql.connector
(...)
-- Run from command line => works
-- Run from Lua => fails / log:
Traceback (most recent call last):
File "/www/test.py", line 4, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
So what am I missing here?
Found an answer here: https://askubuntu.com/questions/1014947/mysql-connector-python-importerror-no-module-named-mysql
should apt-get install python3-mysql.connector
(i.e. not just pip install mysql-connector-python3
)