Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 import module error
I want to execute a python script from a bash script. But I cant import the mysql.connector module when running the script from snmpd. If I run the python or the bash script manually it works fine. But when I run it through snmpwalk I got the following error.

Traceback (most recent call last): File "", line 3, in <module> import mysql.connector ImportError: No module named 'mysql'
my phyton code ""
import sys  
import mysql.connector
	cnx = mysql.connector.connect(user='******', password='*****',
	cursor = cnx.cursor()
	query = "SELECT `Valor`,`Tipo` FROM `snmp` WHERE `OID`='"+sys.argv[1]+"'"
	for (Valor) in cursor:
except mysql.connector.Error as err:
my bash script "panel-current"
if [ "$1" = "-g" ]
echo $2
echo "STRING"
python /usr/local/bin/ $2
exit 0
pass . /bin/bash /usr/local/bin/panel-current
I already checked that it runs on any python version 2.7 and 3.5. I think there is a problem with user permissions and the service is not able to load the mysql.connector module. Can anyone tell me how to fix it?
The error is telling you that mysql is not installed, or at least not foe the version of python that you are running.
You need to install mysql
first make sure that pip is linked with the proper python:
pip -V
if the version of python matches what you are running, install mysql:
pip install mysql
mysql is already installed. And pip is linked to the correct python version. my code does run if I do it manually on every python version my system has. checked with sys.version to make sure the selected one is correct.

But when is used by snmpd the mysql module is always missing. I even tell it to run a specific version of python that I know for sure it has the mysql module installed. but it still missing.
Install for connector is:
pip install mysql-connector-python
(del_env) E:\div_code\del_env
λ pip install mysql-connector-python
Collecting mysql-connector-python
  Downloading .....
Installing collected packages: six, protobuf, mysql-connector-python
Successfully installed mysql-connector-python-8.0.15 protobuf-3.6.1 six-1.12.0

(del_env) E:\div_code\del_env
λ python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> mysql.connector.__version__
Alternative Pure Python MySQL Client PyMySQL.
I ended up using sockets instead. Mysql queries had a memory leak on my nodejs server. Thank you anyway. Maybe later I will test if mysql connector was missing

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  import yaml error for python3 maiya 4 160 Yesterday, 06:07 PM
Last Post: Gribouillis
  Unable to import my own module ThePhantom 3 313 May-01-2020, 01:30 AM
Last Post: menator01
  Which app do I import to fix this error? ErnestTBass 6 405 Apr-26-2020, 08:43 PM
Last Post: snippsat
  Error while humansize module import. johnkgson 3 484 Apr-26-2020, 08:37 AM
Last Post: johnkgson
  from module import function krishanu21 4 250 Apr-22-2020, 10:58 AM
Last Post: buran
  Importing module from a package results in import error goghvv 2 298 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Import Module and Method ( dynamic ) ? JohnnyCoffee 0 202 Mar-23-2020, 04:23 PM
Last Post: JohnnyCoffee
  how to import a module which is installed to personal folder using pip install --pre? geekgeek 2 302 Mar-09-2020, 02:38 PM
Last Post: geekgeek
  module run on import? mcmxl22 3 303 Mar-02-2020, 04:37 PM
Last Post: mcmxl22
  Cannot import list from another module? t4keheart 1 242 Feb-17-2020, 10:25 PM
Last Post: t4keheart

Forum Jump:

Users browsing this thread: 1 Guest(s)