Python Forum
Code hangs in Ubuntu but not in IDE
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code hangs in Ubuntu but not in IDE
#1
I have an app that is using the paramiko library that hangs when I run in ubuntu 16.04. I wrote it in Pycharm using python3 and it works perfectly. When I moved everything over to ubuntu 16.04 it took some changes to get everything installed correctly but I got passed that. Now when I run it will just stop halfway through. Im wondering if it is timing out and not throwing an error.

Do I have something configured wrong? I dont know what part of my code would be beneficial to you? If I need to, I can give you the github page or attach some stuff. 

I am definitely a noob to development so I could be doing something completely wrong.
Reply
#2
I'm looking in my crystal ball, but don't see anything...
Aha, that's it - we need to see some code before (eventually) to be able to advise you.
Reply
#3
What os did it work under, if not ubuntu? What changes did you do to get it to kind-of work? How did you install paramiko on ubuntu? (pip? apt? manually?)
Reply
#4
Just some things to check

I suspect that one (or more) of the methods that you are calling is
waiting for a response.

Quote:I wrote it in Pycharm using python3 and it works perfectly

Are you sure? Are you checking any and all returned error or other messages
(there could be warnings, that are being ignored)

Quote:Do I have something configured wrong?

How would we ever know if you don't show some code? You can remove any
personal information.

Finally - Have you read the docs? http://docs.paramiko.org/en/2.1/
Reply
#5
You can always add a few print statements and move them to narrow down on which instruction it hangs.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#6
Sorry to be vague, I just didnt know what part of my code to submit, Below is the block its stuck on.  To answer some of the questions asked: I wrote it in Windows 10, I installed paramiko and pycrypto using pip3, and lastly I am not sure it is running perfectly in pycharm, just that it runs and exits correctly. 


import socket
import userPassword
import paramiko

import Batching
import GetUser
from GetHosts import hosts

key_dict = {}
user = GetUser.getUser()
l_password = ufitadminPassword.getuserPassword()
l_host = hosts()
l_commands = ["sudo -k chown -R user/home/%s/" % user, "cat /home/%s/.ssh/authorized_keys" % user]
l_user = "user"

generator = Batching.batched(l_host, 10)
generator = list(generator)


def exisingKeys():
    for host in l_host:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        try:
            ssh.connect(host, username=l_user, password=l_password, timeout=5)
        except paramiko.SSHException:
            print("Connection Failed on host %s" % host)
            continue
        except paramiko.AuthenticationException:
            print("authentication Exception on host %s" % host)
            continue
        except socket.error:
            print("Socket Error on host %s" % host)
            continue
        transport = ssh.get_transport()
        print("connected to %s" % host)
        session = transport.open_session()
        session.set_combine_stderr(True)
        session.get_pty()
        for commands in l_commands:
            try:
                session = transport.open_session()
            except socket.error:
                print("Socket Error on host %s" % host)
                continue
            session.set_combine_stderr(True)
            session.get_pty()
            session.exec_command(commands)
            stdin = session.makefile('wb', -1)
            stdout = session.makefile('rb', -1)
            try:
                stdin.write(l_password + '\n')
            except:
                socket.error("Error writing password")
                continue
            stdin.flush()
            print("Verifying Keys for host: %s " % host)
            key_list = []
            for line in stdout.read().splitlines():
                input_line = line
                input_line = input_line.replace(b'[sudo] password for user: ', b'')
                key_individual = str(input_line, 'utf-8')
                key_individual = key_individual.replace(
                    'cat: /home/%s/.ssh/authorized_keys: No such file or directory' % user,
                    'No key exists for this user.')
                key_list.append(key_individual)
                print(key_individual)
        print("Key verified for host: %s" % host)
        print("--------------------------------------------------------------")



        key_dict[host] = key_list
    filterString = "No key exists for this user."
    filteredKeylist = [key for key, values in key_dict.items() if filterString in values]
    return filteredKeylist
Reply
#7
Sounds like the program is waiting for some data or input.
How do you run it? There is mistype in the def exisingKeys():
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  fetching exit status hangs in paramiko saisankalpj 3 1,176 Dec-04-2022, 12:21 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020