fabric can `get`, but can't `run` - python

I'm using python2.7 and fabric to connect to an sftp server.
Here's what I'm doing:
from fabric.api import env, get, run
env.key_filename = '/path/to/keyfile'
env.host_string = 'host.string'
env.user = 'user'
At this point, get('filename') successfully downloads a file from the sftp server. But run('ls') gives me:
[host.string] run: ls
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/fabric/network.py", line 647, in host_prompting_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/fabric/operations.py", line 1054, in run
shell_escape=shell_escape)
File "/usr/local/lib/python2.7/dist-packages/fabric/operations.py", line 923, in _run_command
stderr=stderr, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/fabric/operations.py", line 764, in _execute
channel.get_pty(width=cols, height=rows)
File "/usr/local/lib/python2.7/dist-packages/paramiko/channel.py", line 60, in _check
return func(self, *args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/paramiko/channel.py", line 177, in get_pty
self._wait_for_event()
File "/usr/local/lib/python2.7/dist-packages/paramiko/channel.py", line 1086, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
When I manually log into the sftp server, using the same creds, I can ls just fine.
Any ideas? Thanks.

Related

PyMongo - Server timeout on localhost

I'm trying to learn how to work with MongoDB in Python but everytime I run my code it takes so long that I have to kill it and I get these tracebacks.
"/Volumes/ADATA HD720/flapPY/venv/bin/python" "/Volumes/ADATA HD720/flapPY/Database.py"
Traceback (most recent call last):
File "/Volumes/ADATA HD720/flapPY/Database.py", line 8, in <module>
x = high_scores.insert_one(mydict)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 693, in insert_one
session=session),
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 607, in _insert
bypass_doc_val, session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 595, in _insert_one
acknowledged, _insert_command, session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1247, in _retryable_write
with self._tmp_session(session) as s:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1576, in _tmp_session
s = self._ensure_session(session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session
server_session = self._get_server_session()
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session
return self._topology.get_server_session()
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session
None)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/topology.py", line 208, in _select_servers_loop
self._condition.wait(common.MIN_HEARTBEAT_INTERVAL)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 300, in wait
gotit = waiter.acquire(True, timeout)
KeyboardInterrupt
Process finished with exit code 1
This is my code:
import pymongo
client = pymongo.MongoClient("localhost", 27017)
database = client["database"]
high_scores = database["highscore"]
mydict = {"highscore" : 5}
x = high_scores.insert_one(mydict)
print(x.inserted_id)
My belief is that it cannot connect to the localhost
Apparently mongodb was not started on my PC. All I had to do was to run
brew services start mongodb
and it worked perfectly.

MongoLab/PyMongo connection error

If I run in the shell:
mongo ds0219xx.mlab.com:219xx/dbname -u user -p pass
It works and allows me to connect to the database and pull information. But if I'm within my python application (Flask) and run this:
import pymongo
client = pymongo.MongoClient("mongodb://user:pass#ds0219xx.mlab.com:219xx/dbname")
db = client["dbname"]
db.users.insert_one({
"user1": "hello"
})
It gives me an:
pymongo.errors.OperationFailure: Authentication failed.
I'm pretty sure it's failing before it gets to the insert_one() call, but I'm not completely sure.
Thanks!
Edit:
By request, here is the full callback:
Traceback (most recent call last):
File "run.py", line 1, in <module>
from app import app
File "/Users/Derek/Documents/programming/shenalum/app/__init__.py", line 6, in <module>
from app import views
File "/Users/Derek/Documents/programming/shenalum/app/views.py", line 4, in <module>
from data import get_posts, get_user_info
File "/Users/Derek/Documents/programming/shenalum/app/data.py", line 9, in <module>
"user1": "hello"
File "/usr/local/lib/python2.7/site-packages/pymongo/collection.py", line 622, in insert_one
with self._socket_for_writes() as sock_info:
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 718, in _get_socket
with server.get_socket(self.__all_credentials) as sock_info:
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/site-packages/pymongo/server.py", line 152, in get_socket
with self.pool.get_socket(all_credentials, checkout) as sock_info:
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/site-packages/pymongo/pool.py", line 541, in get_socket
sock_info.check_auth(all_credentials)
File "/usr/local/lib/python2.7/site-packages/pymongo/pool.py", line 306, in check_auth
auth.authenticate(credentials, self)
File "/usr/local/lib/python2.7/site-packages/pymongo/auth.py", line 436, in authenticate
auth_func(credentials, sock_info)
File "/usr/local/lib/python2.7/site-packages/pymongo/auth.py", line 416, in _authenticate_default
return _authenticate_scram_sha1(credentials, sock_info)
File "/usr/local/lib/python2.7/site-packages/pymongo/auth.py", line 188, in _authenticate_scram_sha1
res = sock_info.command(source, cmd)
File "/usr/local/lib/python2.7/site-packages/pymongo/pool.py", line 213, in command
read_concern)
File "/usr/local/lib/python2.7/site-packages/pymongo/network.py", line 99, in command
helpers._check_command_response(response_doc, None, allowable_errors)
File "/usr/local/lib/python2.7/site-packages/pymongo/helpers.py", line 196, in _check_command_response
raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: Authentication failed.
I figured it out. You can do this from the python file and it will work:
connection = pymongo.MongoClient(ab123456.mlab.com, 123456)
db = connection[databasename]
db.authenticate(database_user, database_pass)
Appending /?authSource=admin helped me.
Full Example:
uri = 'mongodb://username:password#r1.example.net:27017/?authSource=admin'
client = MongoClient(uri)
db = client.test
result = db.users.find()
for document in result:
print(document)
Version: pymongo 3.7.2
You need to authenticate after selecting the database for mongo < 4.0

R CMD BATCH script.R ,execution via fabric run() never exits

I have written a fabric script with boto to install a R application on AWS instance. Fedora 23
All the commands using run & sudo function go as expected,
except this one:
#parallel
def install_DvD():
# with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True):
cmd0 = 'R CMD BATCH %s/DvDdependencies.R' % (DvDpackage_location)
run(cmd0)
As you would noticed, I tried using 'warn_only=true', and that did not help. The installation completes successfully with out errors, I check that manually by logging into the instance and eyeballing DvDdependencies.Rout file.
I think for reasons unkonwn to me the R CMD BATCH command does not return the execution back to fabric.
The traceback output from Ctrl^c the fabric process on my local system is:
[ec2-54-172-154-181.compute-1.amazonaws.com] run: R CMD BATCH ~/DvDdependencies.R
[ec2-54-165-109-62.compute-1.amazonaws.com] run: R CMD BATCH ~/DvDdependencies.R
^C
Stopped.
!!! Parallel execution exception under host u'ec2-54-165-109-62.compute-1.amazonaws.com':
!!! Parallel execution exception under host u'ec2-54-172-154-181.compute-1.amazonaws.com':
Process ec2-54-172-154-181.compute-1.amazonaws.com:
Traceback (most recent call last):
File "/usr/lib64/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib64/python2.7/multiprocessing/process.py", line 114, in run
Process ec2-54-165-109-62.compute-1.amazonaws.com:
self._target(*self._args, **self._kwargs)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/tasks.py", line 242, in inner
Traceback (most recent call last):
File "/usr/lib64/python2.7/multiprocessing/process.py", line 258, in _bootstrap
submit(task.run(*args, **kwargs))
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/tasks.py", line 174, in run
return self.wrapped(*args, **kwargs)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/decorators.py", line 181, in inner
self.run()
File "/usr/lib64/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/tasks.py", line 242, in inner
return func(*args, **kwargs)
File "/home/eyebell/local_bin/healX/DvD-installation/fabfile.py", line 70, in install_DvD
run(cmd0)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/network.py", line 649, in host_prompting_wrapper
submit(task.run(*args, **kwargs))
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/tasks.py", line 174, in run
return self.wrapped(*args, **kwargs)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/decorators.py", line 181, in inner
return func(*args, **kwargs)
return func(*args, **kwargs)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/operations.py", line 1056, in run
File "/home/eyebell/local_bin/healX/DvD-installation/fabfile.py", line 70, in install_DvD
run(cmd0)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/network.py", line 649, in host_prompting_wrapper
return func(*args, **kwargs)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/operations.py", line 1056, in run
shell_escape=shell_escape)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/operations.py", line 925, in _run_command
stderr=stderr, timeout=timeout)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/operations.py", line 811, in _execute
time.sleep(ssh.io_sleep)
KeyboardInterrupt
shell_escape=shell_escape)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/operations.py", line 925, in _run_command
stderr=stderr, timeout=timeout)
File "/home/eyebell/local_bin/healX/DvD-installation/py2fabvirt/lib/python2.7/site-packages/fabric/operations.py", line 811, in _execute
time.sleep(ssh.io_sleep)
KeyboardInterrupt
The complete script is here in my github repo,
the location of DvDdependencies.R (the script that I want to install)
Any comments, help or pointers in right direction are appreciated.
I am closing this, as the issue is with this script only.
Also the installation method for DvD tool has been updated,
hence this is not of interest anymore.

web2py firebird db fails connect

I trying to connect a web2py app to a firebird database in another server.
This is the output message:
Ticket ID
127.0.0.1.2016-01-11.12-27-33.cdefb9f6-3cc5-46ce-85dc-a2a12220e7f6
Failure to connect, tried 5 times:
Traceback (most recent call last): File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/base.py",
line 435, in init self._adapter = ADAPTERSself._dbname
File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/adapters/base.py",
line 53, in call obj = super(AdapterMeta, cls).call(*args,
**kwargs) File "/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/adapters/firebird.py",
line 121, in init if do_connect: self.reconnect() File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/connection.py",
line 105, in reconnect self.connection = f() File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/packages/dal/pydal/adapters/firebird.py",
line 119, in connector return self.driver.connect(**driver_args) File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/contrib/pypyodbc.py",
line 2434, in init self.connect(connectString, autocommit, ansi,
timeout, unicode_results, readonly) File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/contrib/pypyodbc.py",
line 2483, in connect check_success(self, ret) File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/contrib/pypyodbc.py",
line 988, in check_success ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h,
ret, ODBC_obj.ansi) File
"/home/filhofilha/Documents/Deployment/Web2Py/web2py/gluon/contrib/pypyodbc.py",
line 964, in ctrl_err raise Error(state,err_text) Error: (u'IM012',
u'[IM012] [unixODBC][Driver Manager]DRIVER keyword syntax error')
My Code:
dbExternal = DAL('firebird://user:password#localhost/C:\\DB.FDB', migrate_enabled=False)
how can I fix it ?
Thanks
I was missing the python firebird driver. I installed it to correct my problem

bzr unable to connect to ssh host (because of python?)

Until today, I have been able to use bzr pull server:path/to/trunk, but today I get an error:
Unable to connect to SSH host server; EOF during negotiation
It is not clear why this error occurs, but this is the traceback from ~/.bzr.log
Any ideas about how to fix this?
Mon 2011-02-21 16:36:04 -0600
0.022 bazaar version: 2.1.1
0.022 bzr arguments: [u'pull']
0.026 looking for plugins in /home/user/.bazaar/plugins
0.026 looking for plugins in /usr/lib/python2.6/dist-packages/bzrlib/plugins
0.062 encoding stdout as sys.stdout encoding 'UTF-8'
0.133 opening working tree '/home/user/pecan'
0.178 ssh implementation is OpenSSH
0.697 Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/bzrlib/commands.py", line 853, in exception_to_return_code
return the_callable(*args, **kwargs)
File "/usr/lib/python2.6/dist-packages/bzrlib/commands.py", line 1055, in run_bzr
ret = run(*run_argv)
File "/usr/lib/python2.6/dist-packages/bzrlib/commands.py", line 661, in run_argv_aliases
return self.run_direct(**all_cmd_args)
File "/usr/lib/python2.6/dist-packages/bzrlib/commands.py", line 665, in run_direct
return self._operation.run_simple(*args, **kwargs)
File "/usr/lib/python2.6/dist-packages/bzrlib/cleanup.py", line 122, in run_simple
self.cleanups, self.func, *args, **kwargs)
File "/usr/lib/python2.6/dist-packages/bzrlib/cleanup.py", line 156, in _do_with_cleanups
result = func(*args, **kwargs)
File "/usr/lib/python2.6/dist-packages/bzrlib/builtins.py", line 993, in run
possible_transports=possible_transports)
File "/usr/lib/python2.6/dist-packages/bzrlib/branch.py", line 169, in open
possible_transports=possible_transports)
File "/usr/lib/python2.6/dist-packages/bzrlib/bzrdir.py", line 843, in open
return BzrDir.open_from_transport(t, _unsupported=_unsupported)
File "/usr/lib/python2.6/dist-packages/bzrlib/bzrdir.py", line 873, in open_from_transport
redirected)
File "/usr/lib/python2.6/dist-packages/bzrlib/transport/__init__.py", line 1644, in do_catching_redirections
return action(transport)
File "/usr/lib/python2.6/dist-packages/bzrlib/bzrdir.py", line 860, in find_format
transport, _server_formats=_server_formats)
File "/usr/lib/python2.6/dist-packages/bzrlib/bzrdir.py", line 1820, in find_format
return format.probe_transport(transport)
File "/usr/lib/python2.6/dist-packages/bzrlib/bzrdir.py", line 1830, in probe_transport
format_string = transport.get_bytes(".bzr/branch-format")
File "/usr/lib/python2.6/dist-packages/bzrlib/transport/sftp.py", line 435, in get_bytes
f = self.get(relpath)
File "/usr/lib/python2.6/dist-packages/bzrlib/transport/sftp.py", line 425, in get
f = self._get_sftp().file(path, mode='rb')
File "/usr/lib/python2.6/dist-packages/bzrlib/transport/sftp.py", line 397, in _get_sftp
connection, credentials = self._create_connection()
File "/usr/lib/python2.6/dist-packages/bzrlib/transport/sftp.py", line 389, in _create_connection
self._host, self._port)
File "/usr/lib/python2.6/dist-packages/bzrlib/transport/ssh.py", line 376, in connect_sftp
self._raise_connection_error(host, port=port, orig_error=e)
File "/usr/lib/python2.6/dist-packages/bzrlib/transport/ssh.py", line 252, in _raise_connection_error
orig_error=orig_error)
SocketConnectionError: Unable to connect to SSH host server; EOF during negotiation
0.698 Transferred: 0KiB (0.0K/s r:0K w:0K)
0.698 return code 3
This error was caused because I had added
alias bzr status='bzr status -V'
to .bashrc, and bzr status is an invalid alias name that presumably confused the server's bzr
A bug report to bzr indicates that a similar error can be caused by changes to the server's firewall settings

Categories