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.
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
Related
I am trying to run my python app on my website, and so I've created a virtual environment for all of the packages, and I've correctly installed all of the packages I need. When I check on the file path to my installed packages, they are all pointing to the correct path, and when I got to my site-packages file that they point to, they are all there.
However,
Every time I try to run my app, I get this:
stdin: is not a tty
Traceback (most recent call last):
File "/opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 369, in <module>
app_module = load_app()
File "/opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 76, in load_app
return imp.load_source('passenger_wsgi', startup_file)
File "/home/dsmproto/testblockchain/passenger_wsgi.py", line 1, in <module>
import main as application
File "/home/dsmproto/testblockchain/main.py", line 2, in <module>
from wallet import wallet
File "/home/dsmproto/testblockchain/wallet.py", line 1, in <module>
from Cryptodome.PublicKey import RSA
ImportError: No module named Cryptodome.PublicKey
I know that the module is there, but for some reason it is still saying there's no module.
Is there a command I can use in my SSH to check where my app is looking for modules?
All of the modules I have installed are installed correctly. Furthermore, when I open the SSH and run python commands in the terminal, they are able to import all of the modules without any issues.
So how come my app can't find these modules? Is there a way to check to make sure they are looking in the right place?
Thanks in advance for the help
EDIT:
I ran a script in python to look at the sys.path and got this:
/opt/alt/python38/lib64/python38.zip
/opt/alt/python38/lib64/python3.8
/opt/alt/python38/lib64/python3.8/lib-dynload
/home/dsmproto/virtualenv/testblockchain/3.8/lib64/python3.8/site-packages
/home/dsmproto/virtualenv/testblockchain/3.8/lib/python3.8/site-packages
Those are the correct folders that my packages are installed in, yet when I try to run my app, it still says it can't find them.
Working on code that SSH's into terminal on an external device. This morning the code was able to do so. Then I updated Windows because I had put it off for a while. This was the only thing I did that I could think of may have had an effect.
I now run into a ModuleNotFoundError.
I tried updating pip, uninstalling and reinstalling ssh2-python. I changed python37 folder to read/write. Tried locating the module in python37/Lib/site-packages but not really sure what I'm looking for
SSH's into address' terminal
import socket
from ssh2.session import Session
Expected:
input for ip address
Result:
Traceback (most recent call last):
File "C:/Users/louis/Desktop/ssh2.py", line 4, in <module>
from ssh2.session import Session
File "C:\Users\louis\Desktop\ssh2.py", line 4, in <module>
from ssh2.session import Session
ModuleNotFoundError: No module named 'ssh2.session'; 'ssh2' is not a package
I had named a file in the same directory ssh2. Python loaded that instead of the module. Simply renamed the file to anything else and python was able to find the ssh2 module.
I am trying to execute a small python code from CPP environment(Visual studio 2008) for test automation. When I try to add the following code in python script import socket. The python code is not getting imported. I am getting the below error.
Py_initialize succeededTraceback (most recent call last):
File "E:\Code\MSVC\PythonTest\Proj\Pythoncheck\Debug\main.py", line 2, in <module>
import socket
File "C:\Python27\Lib\socket.py", line 47, in <module>
import _socket
ImportError: No module named _socket
But when i execute the python script alone(python main.py), there is no such issue in importing socket. The python script is getting executed fine. Has anyone faced this earlier? Could anyone help me with the solution?
The code main.py contains
import sys
import socket
print"santhosh"
def startmain():
while True:
time.sleep(5000)
pingcount = 0
print "InstartMain"
Regards,
Santhosh
The environment where you are launching python might not be the same as the environment where you are launching your CPP program. Try setting PYTHONHOME
[I know this won't help the original poster, but I ran into this issue trying to use pythonnet from C# in 2018]
Somehow my python is broken and emits the error:
jseidel#EDP15:/etc/default$ python -c 'import random'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
This is NOT the virtualenv error that is so commonly documented here and elsewhere: I don't use python directly, I have never setup a virtualenv explicitly, and there is no virtualenv directory or python script that I can find anywhere on my system.
I'm running Kubuntu 10.04 and until just recently my KPackageKit worked just fine and handled updates with no problem. Now it shows nothing... maybe because of this python error, maybe because of something else.
How do I go about finding the error and fixing python?
As suggested by #Armin Rigo, this worked for me:
1) Add a print 42 at the end of the /usr/lib/python2.6/os.py file.
2) If you see "42", then that is the correct os.py file and the urandom module is not include. Add the statement to include urandom (you can find a sample from another os.py file). This was what worked for me.
3) If you don't see "42", then that's not the os.py file that you're using. Find the random.py file that is crashing and insert import os; print os.__file__ to get more information about the failure.
I have installed CherryPy 3.1.0,. Here is what happens when I try to run tutorial 9:
$ cd /Library/Python/2.5/site-packages/cherrypy/tutorial/
$ python tut09_files.py
Traceback (most recent call last):
File "tut09_files.py", line 48, in <module>
from cherrypy.lib import static
ImportError: cannot import name static
The previous line in the file:
import cherrypy
passes without error, so it appears that it can find cherrypy on the path. What am I missing?
This works for me, and I'm also using CherryPy 3.1.0, so I'm not sure what to tell you.
Look in your /Library/Python/2.5/site-packages/cherrypy/lib directory for a file named static.py; if this file exists then I'm not sure what to tell you. If it doesn't then something has happened to your CherryPy and I'd advise you to reinstall. If it does then you should check the value of sys.path to make sure it's detecting the right version of CherryPy.
You can also try running the python interpreter on the command line and then doing a from cherrypy.lib import static to see if you get the same result.
I had an old CherryPy-2.3.0-py2.5.egg file in my site-packages. After removing the old .egg I could run the tutorial.