Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
import module error
#1
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.

Error:
Traceback (most recent call last): File "parser.py", line 3, in <module> import mysql.connector ImportError: No module named 'mysql'
my phyton code "parser.py"
#!/usr/bin/python 
import sys  
import mysql.connector
try:
	cnx = mysql.connector.connect(user='******', password='*****',
								  host='127.0.0.1',
								  database='******')
	cursor = cnx.cursor()
	query = "SELECT `Valor`,`Tipo` FROM `snmp` WHERE `OID`='"+sys.argv[1]+"'"
	imp="0"
	tipo="INTEGER"
	cursor.execute(query)
	for (Valor) in cursor:
		imp=Valor[0]
		tipo=Valor[1]
	print(tipo)
	print(imp)
	cursor.close()
except mysql.connector.Error as err:
		print(-1)
else:
	cnx.close();
my bash script "panel-current"
#!/bin/bash
if [ "$1" = "-g" ]
then
echo $2
echo "STRING"
python /usr/local/bin/parser.py $2
fi
exit 0
snmpd.conf
pass .1.3.6.1.4.1.2020.1 /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?
Reply


Messages In This Thread
import module error - by german77 - Feb-26-2019, 01:57 AM
RE: import module error - by Larz60+ - Feb-26-2019, 05:18 AM
RE: import module error - by german77 - Feb-26-2019, 03:08 PM
RE: import module error - by snippsat - Feb-26-2019, 03:41 PM
RE: import module error - by german77 - Feb-28-2019, 02:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  is import cointegration_analysis a recognized module mitcht33 1 429 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,404 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 719 Aug-06-2023, 01:09 AM
Last Post: aupres
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,766 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  import module error tantony 5 3,451 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,079 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Cryptic Error with import statement Led_Zeppelin 2 2,546 Jan-11-2022, 01:13 PM
Last Post: Led_Zeppelin
  Install any library via pip get an error cannot import name 'SCHEME_KEYS' from 'pip. Anldra12 2 10,637 Jan-04-2022, 01:05 PM
Last Post: Anldra12
  Import a module for use in type hint? Milosz 0 1,486 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 2,805 Oct-27-2021, 03:32 AM
Last Post: Tek

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020