Avatar of Ingo Brown
Ingo Brown
Flag for Spain asked on

To enter strings into a keyboard, press carriage return, and have the string append a remote mySQL database

Issue:
Python Script will not run because sshtunnel import to Python 3 does not seem import properly to the Pi.
I am thinking we are using the wrong version of ssh module python script for the Pi but I am struggling.  

 Hardware :
Raspberry Pi 3 Model B -  V 1.2  2015

OS Software :
pi@raspberrypi:~ $ cat /etc/*-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian

Script:
import sshtunnel #import SSHTunnelForwarder
import mysql.connector

ID_String_Last = ["0"]

sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0

with sshtunnel.SSHTunnelForwarder(
    ('**********this is the host in here **********'),
    ssh_username='', ssh_password='**********************',
    remote_bind_address=('127.0.0.1,', 3306)
) as tunnel:
    connection = mysql.connector.connect(
        user='*********username**********', password='*****************',
        host='127.0.0.1', port=tunnel.local_bind_port,
        database='northgm7_489.log_1001',
    )


Output:
Python 3.4.2 (/usr/bin/python3)
>>> %Run '17-10- 15 V6.1 Pi mySQL to Ash server.py'
Traceback (most recent call last):
  File "/home/pi/Desktop/17-10- 15 V6.1 Pi mySQL to Ash server.py", line 3, in <module>
    import sshtunnel #import SSHTunnelForwarder
ImportError: No module named 'sshtunnel'


Question:
Does anybody know what version of module is required for this platform so that it can  run?
LinuxDatabasesPythonHardwareSSH / Telnet Software

Avatar of undefined
Last Comment
NerdsOfTech

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
NerdsOfTech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ingo Brown

ASKER
Apologies for the delay in response. I will give this a try this afternoon and revert
NerdsOfTech

SSH forwarder should do the trick
Ingo Brown

ASKER
We could not get the module to work so we assumed we had a OS problem. We downloaded the latest version of  UBUNTU 16.04 LTS to the rasberry pi. When I run sudo -H pip install sshtunnel , I get the following error:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-wmbw0/pynacl/

We are struggling with the module itself it seems
we are such noobs!!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
NerdsOfTech

try:

sudo apt-get install python-setuptools
sudo easy_install -U setuptools
sudo pip install --upgrade setuptools
python setup.py egg_info

Open in new window

Ingo Brown

ASKER
We got the modules installed & below is the script that works.

from sshtunnel import SSHTunnelForwarder
import MySQLdb

user_entry = input("Please enter user: ")

with SSHTunnelForwarder(('bo************.com', 22),
                        ssh_password='*****************!', ssh_username='***********',
                        remote_bind_address=('localhost', 3306)) as server:
    conn = MySQLdb.connect('**********t.com', '*****************c', '*****************', '**************')
    cursor = conn.cursor()
    cursor.execute("INSERT INTO log_1001(user) VALUES('%s')" % user_entry)
    cursor.execute("SELECT * FROM log_1001")
    for row in cursor.fetchall():
        print(row)
NerdsOfTech

Thanks for the update!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.