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?
Ingo BrownOwnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NerdsOfTechTechnology ScientistCommented:
try replacing this line
import sshtunnel #import SSHTunnelForwarder

Open in new window

with:
import sshtunnel 
from sshtunnel import SSHTunnelForwarder

Open in new window

OR, if that doesn't work try:
import paramiko
from sshtunnel import SSHTunnelForwarder

Open in new window


https://github.com/pahaz/sshtunnel/blob/master/README.rst
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ingo BrownOwnerAuthor Commented:
Apologies for the delay in response. I will give this a try this afternoon and revert
0
NerdsOfTechTechnology ScientistCommented:
SSH forwarder should do the trick
0
Ingo BrownOwnerAuthor Commented:
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!!
0
NerdsOfTechTechnology ScientistCommented:
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

0
Ingo BrownOwnerAuthor Commented:
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)
1
NerdsOfTechTechnology ScientistCommented:
Thanks for the update!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.