Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:24:44+00:00 2026-06-10T02:24:44+00:00

This is a question about a command which works in pythons interactive mode over

  • 0

This is a question about a command which works in pythons interactive mode over SSH, but not if included in a script. It is driving me mad. I have been having problems with the script, but now I have discovered that I can simply put the lines into the python shell and I get the exact result I was expecting! This is confusing me, and I don’t know how to proceed because I need it to work in a script. For the python shell, I log in via SSH, and then open a python script rather than login via the python ssh module. From there, it works exactly as expected.

import ssh
import gnupg
import pickle

s = ssh.Connection(host = 'ipaddress', username = 'toolserv', password = 'xxxx') 

gpg = gnupg.GPG(gnupghome="/home/toolserv/.gnupg") 

with open("result1.txt", "r") as my_file:
    signed_data1 = pickle.load(my_file)
    my_file.close()

print signed_data1

s.close()

If I execute the script as from sudo the error I get from the script is:

Traceback (most recent call last):
  File "sshx.py", line 11, in <module>
    with open("result1.txt", "r") as my_file:
IOError: [Errno 2] No such file or directory: 'result1.txt

ls -ld gives the following result:
drwxr-xr-x 29 toolserv toolserv 4096 2012-08-19 22:38

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:24:45+00:00Added an answer on June 10, 2026 at 2:24 am

    Initial answer

    Your script is getting executed on your local host, not on your target server. Notice how you open an SSH session and then don’t use it.

    The toolserv user likely doesn’t exist on this host. Hence the error when gnupg tries to create the directory.

    In reaction to your comment:

    Let me make this clearer. Merely calling s = ssh.Connection(host = 'ipaddress', username = 'toolserv', password = 'xxxx') does not mean that all subsequent code will be executed on the remote host.

    Right now, what you code does is the following:

    1. Connect to the remote host at ipaddress through SSH
    2. Use the gnupg lib with the keys located at /home/toolserv/.gnupg on the local host.
    3. Read some (pickled?) file’s content that is on your local host.
    4. Print that (unpickled) content
    5. Close the SSH connection (without ever using it).

    You never use the SSH connection, this is probably not what you want and probably why your script is failing.

    Of course, if you execute the exact same script on your remote host by login in through SSH and then using the shell, your local host is actually the remote host, so it works. However, the fact that the code works when executed from your remote host is nothing more than an coincidence.

    One last time, your script probably does not do what you think it does, and unless you investigate that, it’s never going to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Followed this question about delayed_job and monit Its working on my development machine. But
Note: I originally asked this question about an hour ago but only recently realized
I've this question about pass some instances by ref or not: here is my
JD Long helped me with this: question about manual annotation . But is it
Okay, now this is more a rant about Linux than a question, but maybe
This question about Timers for windows services got me thinking: Say I have (and
I have seen this question about deploying to WebSphere using the WAS ant tasks.
Follow up to this question about GNU make : I've got a directory, flac
This is sort of the Java analogue of this question about C# . Suppose
A few days ago I asked this question about jquery ajax function invoking action

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.