I am trying to get the directory structure for a FTP user remotely. I am doing this from a python script using [spur][1] module. I am calling this script using a cron job. But I am getting the following
Traceback (most recent call last):
File "/mnt/voylla-staging/releases/20140717193920/voylla_scripts/snapdeal/GetOrders/getOrders.py", line 54, in <module>
feeds = getFeeds()
File "/mnt/voylla-staging/releases/20140717193920/voylla_scripts/snapdeal/GetOrders/getOrders.py", line 26, in getFeeds
result = shell.run(["ls", FEED_LOCATION])
File "/usr/local/lib/python2.7/dist-packages/spur/ssh.py", line 73, in run
return self.spawn(*args, **kwargs).wait_for_result()
File "/usr/local/lib/python2.7/dist-packages/spur/ssh.py", line 83, in spawn
channel = self._get_ssh_transport().open_session()
File "/usr/local/lib/python2.7/dist-packages/spur/ssh.py", line 190, in _get_ssh_transport
raise self._connection_error(error)
spur.ssh.ConnectionError: Error creating SSH connection
Original error: Authentication failed.
If I run the scipt manually without using the cron, its runs perfectly fin!
Please can someone help.
Thanks
Relevant Code:
FTP_SERVER = "abc.example.com"
FTP_USER = "root"
FEED_LOCATION = "/home/xyz/abc"
PROCESSED_FEED_LOCATION = "/home/xyz/def"
PREFIX = "alpha"
def getFeeds(): ####returns the list of feeds in FEED_LOCATION
shell = spur.SshShell(hostname=FTP_SERVER, username=FTP_USER)
with shell:
result = shell.run(["ls", FEED_LOCATION])
feeds = result.output.decode().split("\n")
return feeds
feeds = getFeeds()
You have to specify the path of your private key file with the private_key_file option. Here is the example from the documentation.
# Use a private key
spur.SshShell(
hostname="localhost",
username="bob",
private_key_file="path/to/private.key"
)
Related
I'm trying to use Couchbase Python SDK 3.0.x to connect to a cluster. I followed the document (https://docs.couchbase.com/python-sdk/3.0/howtos/managing-connections.html#ssl) to create the certificate file and used it with the following code:
cluster = Cluster("couchbase://10.82.xxx.xxx:18091", ClusterOptions(PasswordAuthenticator(DEST_USR, DEST_PW, cert_path="./cert.crt")))
However when I run it it gives the following:
$ python3 mycode.py
creating couchbase instance seriesMgmt#10.82.xxx.xxx:18091
Traceback (most recent call last):
File "scheduleCache.py", line 29, in <module>
cluster = Cluster("couchbase://"+DEST_CB_IP, ClusterOptions(PasswordAuthenticator(DEST_USR, DEST_PW, cert_path="./cert.crt")))
File "/usr/local/lib/python3.7/site-packages/couchbase/cluster.py", line 492, in __init__
super(Cluster, self).__init__(connection_string=str(self.connstr), _conntype=_LCB.LCB_TYPE_CLUSTER, **self._clusteropts)
File "/usr/local/lib/python3.7/site-packages/couchbase_core/client.py", line 141, in __init__
super(Client, self).__init__(*args, **kwargs)
couchbase.exceptions.InvalidArgumentException: <Bad/insufficient arguments provided, inner_cause='certpath' is an invalid keyword argument for this function, C Source=(src/bucket.c,1047)>
I believe it's not about the correctness of my cert file yet - somehow the SDK just doesn't want to take the parameter cert_path. Tried to remove the parameter name and it doesn't help:
cluster = Cluster("couchbase://10.82.xxx.xxx:18091", ClusterOptions(PasswordAuthenticator(DEST_USR, DEST_PW, "./cert.crt")))
BTW I can login https://10.82.xxx.xxx:18091 via browser without any problem.
I have Asterisk 13.20 set up and running fine on Ubuntu 16.04,calls are going well through a Softphone(Zoiper), I came across a Library in Python "Pycall" which lets you make calls through a Python Script.So I tried testing a snippet from the site Pycall
The code that I used:
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()
Just made changes in the extension,wherein I used one from my server
However I am getting the following error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
c.spool()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 131, in spool
self.writefile()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 119, in writefile
f.write(self.contents)
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 114, in contents
return '\n'.join(self.buildfile())
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
raise ValidationError
pycall.errors.ValidationError
Tried searching online for the solution but coudnt find one,What am I doing wrong?
This question not related to PBX, it is just incorrect use of LIB.
General instruction how to solve ANY issue with availible source code.
You have error
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
Go that file and line, check code, add more debug if needed, fix your app.
Run as asterisk user.
sudo su asterisk -s /bin/bash
python
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()
I am trying to do parallel ssh on servers. While doing this, i am getting "TypeError: 'NoneType' object is not iterable" this error. Kindly help.
My script is below
from pssh import ParallelSSHClient
from pssh.exceptions import AuthenticationException, UnknownHostException, ConnectionErrorException
def parallelsshjob():
client = ParallelSSHClient(['10.84.226.72','10.84.226.74'], user = 'root', password = 'XXX')
try:
output = client.run_command('racadm getsvctag', sudo=True)
print output
except (AuthenticationException, UnknownHostException, ConnectionErrorException):
pass
#print output
if __name__ == '__main__':
parallelsshjob()
And the Traceback is below
Traceback (most recent call last):
File "parallelssh.py", line 17, in <module>
parallelsshjob()
File "parallelssh.py", line 10, in parallelsshjob
output = client.run_command('racadm getsvctag', sudo=True)
File "/Library/Python/2.7/site-packages/pssh/pssh_client.py", line 520, in run_command
raise ex
TypeError: 'NoneType' object is not iterable
Help me with the solution and also suggest me to use ssh-agent in this same script. Thanks in advance.
From reading the code and debugging a bit on my laptop, I believe the issue is that you don't have a file called ~/.ssh/config. It seems that parallel-ssh has a dependency on OpenSSH configuration, and this is the error you get when that file is missing.
read_openssh_config returns None here: https://github.com/pkittenis/parallel-ssh/blob/master/pssh/utils.py#L79
In turn, SSHClient.__init__ blows up when trying to unpack the values it expects to receive: https://github.com/pkittenis/parallel-ssh/blob/master/pssh/ssh_client.py#L97.
The fix is presumably to get some sort of OpenSSH config file in place, but I'm sorry to say I know nothing about that.
EDIT
After cleaning up some of parallel-ssh's exception handling, here's a better stack trace for the error:
Traceback (most recent call last):
File "test.py", line 11, in <module>
parallelsshjob()
File "test.py", line 7, in parallelsshjob
output = client.run_command('racadm getsvctag', sudo=True)
File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 517, in run_command
self.get_output(cmd, output)
File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 601, in get_output
(channel, host, stdout, stderr, stdin) = cmd.get()
File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 480, in get
self._raise_exception()
File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 171, in _raise_exception
reraise(*self.exc_info)
File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/gevent/greenlet.py", line 534, in run
result = self._run(*self.args, **self.kwargs)
File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/pssh_client.py", line 559, in _exec_command
channel_timeout=self.channel_timeout)
File "/Users/smarx/test/pssh/venv/lib/python2.7/site-packages/pssh/ssh_client.py", line 98, in __init__
host, config_file=_openssh_config_file)
TypeError: 'NoneType' object is not iterable
This was seemingly a regression in the 0.92.0 version of the library which is now resolved in 0.92.1. Previous versions also work. OpenSSH config should not be a dependency.
To answer your SSH agent question, if there is one running and enabled in the user session it gets used automatically. If you would prefer to provide a private key programmatically can do the following
from pssh import ParallelSSHClient
from pssh.utils import load_private_key
pkey = load_private_key('my_private_key')
client = ParallelSSHClient(hosts, pkey=pkey)
Can also provide an agent with multiple keys programmatically, per below
from pssh import ParallelSSHClient
from pssh.utils import load_private_key
from pssh.agent import SSHAgent
pkey = load_private_key('my_private_key')
agent = SSHAgent()
agent.add_key(pkey)
client = ParallelSSHClient(hosts, agent=agent)
See documentation for more examples.
I am trying to run the Face Detection Example in Google's Cloud Vision API. I am trying to run [faces.py here][1].
When I run the following:
faces.py demo-picture.jpg
below is the error I get:
ubuntu#ubuntu-VirtualBox:~/Documents/code/python- stuff/googleapis/cloudvisionapi/cloud-vision/python/face_detection$ python faces.py demo-image.jpg
Traceback (most recent call last):
File "faces.py", line 121, in <module>
main(args.input_image, args.output, args.max_results)
File "faces.py", line 98, in main
faces = detect_face(image, max_results)
File "faces.py", line 62, in detect_face
service = get_vision_service()
File "faces.py", line 35, in get_vision_service
credentials = GoogleCredentials.get_application_default()
File "/home/ubuntu/.local/lib/python2.7/site- packages/oauth2client/client.py", line 1398, in get_application_default
return GoogleCredentials._get_implicit_credentials()
File "/home/ubuntu/.local/lib/python2.7/site- packages/oauth2client/client.py", line 1388, in _get_implicit_credentials
raise ApplicationDefaultCredentialsError(ADC_HELP_MSG)
oauth2client.client.ApplicationDefaultCredentialsError: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application- default-credentials for more information.
ubuntu#ubuntu-VirtualBox:~/Documents/code/python- stuff/googleapis/cloudvisionapi/cloud-vision/python/face_detection$
[1]: https://github.com/GoogleCloudPlatform/cloud- vision/tree/master/python/face_detection
I guess my question is -- how do I do this:
Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.
You need to download the service-account key; typically a JSON file.
If you have not created the credentials/obtained the key, follow the steps:
Go to your API manager;
Create credentials;
Choose "Service Account Key";
Select "Key Type" as JSON.
After this point, you should obtain a JSON file.
Once you obtain the key, go to your BASHRC (~/.bashrc) and add the following:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/JSON
Then restart your bash by
exec bash
Now, re-run your faces.py.
I'm trying to connect to connect to amazon EC2 via fabric using the script below. But I'm met with a problem that I'm not sure how to solve it.
import os
from fabric.api import run, env, local, cd
WORK = os.getenv('HOME') + '/Work/myproject/'
env.user = 'ubuntu'
env.hosts = [
'128.248.268.288'
]
env.key_filename = [
'%s/aws/myproject.pem' % WORK
]
def deploy():
print("Executing on %(host)s as %(user)s" % env)
with cd('/sites/myproject.com/code/'):
run('ls')
This is the traceback. I'm not sure how to solve the problem.
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/fabric/main.py", line 540, in main
commands[name](*args, **kwargs)
File "/Users/mickeyckm/Work/myproject/codes/giivee/fabfile.py", line 18, in deploy
run('ls')
File "/Library/Python/2.6/site-packages/fabric/network.py", line 391, in host_prompting_wrapper
return func(*args, **kwargs)
File "/Library/Python/2.6/site-packages/fabric/operations.py", line 422, in run
channel = connections[env.host_string]._transport.open_session()
File "/Library/Python/2.6/site-packages/fabric/network.py", line 65, in __getitem__
self[real_key] = connect(user, host, port)
File "/Library/Python/2.6/site-packages/fabric/network.py", line 140, in connect
client.load_system_host_keys()
File "/Library/Python/2.6/site-packages/paramiko/client.py", line 151, in load_system_host_keys
self._system_host_keys.load(filename)
File "/Library/Python/2.6/site-packages/paramiko/hostkeys.py", line 155, in load
e = HostKeyEntry.from_line(line)
File "/Library/Python/2.6/site-packages/paramiko/hostkeys.py", line 67, in from_line
key = RSAKey(data=base64.decodestring(key))
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/base64.py", line 321, in decodestring
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
Any help/hint would be great appreciated.
Cheers,
Mickey
I saw some places where Incorrect Padding error was resulted from binascii module and it was mostly when the string you pass has some extraneous white-space characters.
>>> import binascii
>>> binascii.a2b_base64('a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
binascii.Error: Incorrect padding
In your case, it the various properties you set for your env object. Do something like this for your key file location and see if that works.
filelocation = os.path.join(WORK,'aws/myproject.pem')
env.key_filename = [filelocation]
Look at your ~/.ssh/known_hosts file. It may contain lines with duplicate entries or be corrupted in some other way.
I had a similar problem and tracked it down to some corruption in my .ssh/known_hosts file.
I thus added to my .bashrc
alias deploy='mv ~/.ssh/known_hosts ~/.ssh/known_hosts.tmp; fab <myfabscript>; mv ~/.ssh/known_hosts.old ~/.ssh/known_hosts'
(obviously putting the right fabric script where <myfabscript> is) and now all works fine when I simply run "deploy"!