0

I am running the source version of web2py from an Ubuntu VM and Python 2.7. I'm trying to use the Paramiko library for SSH functionality, but the following code gives this error:

Code

from paramiko import client

Error

Traceback (most recent call last):
  File "/home/localadmin/scanme/gluon/restricted.py", line 227, in restricted
    exec ccode in environment
  File "/home/localadmin/scanme/applications/nmap/controllers/default.py", line 418, in <module>
  File "/home/localadmin/scanme/gluon/globals.py", line 417, in <lambda>
    self._caller = lambda f: f()
  File "/home/localadmin/scanme/applications/nmap/controllers/default.py", line 50, in login
    except paramiko.ssh_exception.AuthenticationException:
NameError: global name 'paramiko' is not defined

What is confusing me is that importing and using the paramiko library works perfectly fine on my system when I run Python outside of web2py.

I thought that all modules available in my local Python install were supposed to be available in web2py when using the source version. This is how i launched the web server from the command line:

python2.7 web2py.py

Does anyone know what may be causing this issue? It's worth noting that I have not found a "paramiko" directory on my system after installing the library like I have with other modules that are working in web2py.

wake-0
  • 3,918
  • 5
  • 28
  • 45
B Welch
  • 15
  • 1
  • 7

1 Answers1

4

Your import statement is:

from paramiko import client

But in your code, you have:

except paramiko.ssh_exception.AuthenticationException

In order to reference paramiko, you must import it:

import paramiko
Anthony
  • 25,466
  • 3
  • 28
  • 57
  • I tried that and now the error happens in this line: `session.connection = ssh(credentials.vars.host_address, credentials.vars.username, credentials.vars.password)` and says "** global name 'ssh' is not defined**" – B Welch Jun 30 '16 at 14:32
  • Never mind, I figured out the issue. I didn't realize that when I copied the script over from my local machine into web2py, I didn't copy the part where I defined the class "**ssh**". Thanks! – B Welch Jun 30 '16 at 14:42