Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'SshMachine' object has no attribute 'env' #293

Closed
schtibe opened this issue Aug 30, 2016 · 3 comments
Closed

AttributeError: 'SshMachine' object has no attribute 'env' #293

schtibe opened this issue Aug 30, 2016 · 3 comments

Comments

@schtibe
Copy link

schtibe commented Aug 30, 2016

I'm trying to Ssh on a remote machine, and get following error:

Traceback (most recent call last):
  File "wakeonlan", line 49, in <module>
    main()
  File "wakeonlan", line 44, in main
    wake_remotely(args.host)
  File "wakeonlan", line 30, in wake_remotely
    globals()[func_name]()
  File "wakeonlan", line 22, in remote_wake_huckfinn
    with SshMachine("host", user="user") as rem:
  File "/usr/lib/python3.5/site-packages/plumbum/machines/ssh_machine.py", line 106, in __init__
    new_session = new_session)
  File "/usr/lib/python3.5/site-packages/plumbum/machines/remote.py", line 164, in __init__
    self.env = RemoteEnv(self)
  File "/usr/lib/python3.5/site-packages/plumbum/machines/remote.py", line 38, in __init__
    BaseEnv.__init__(self, self.remote.path, ":")
  File "/usr/lib/python3.5/site-packages/plumbum/machines/env.py", line 37, in __init__
    self._update_path()
  File "/usr/lib/python3.5/site-packages/plumbum/machines/env.py", line 40, in _update_path
    self._path.update(self.get("PATH", ""))
  File "/usr/lib/python3.5/site-packages/plumbum/machines/env.py", line 24, in update
    self[:] = [self._path_factory(p) for p in text.split(self._pathsep)]
  File "/usr/lib/python3.5/site-packages/plumbum/machines/env.py", line 24, in <listcomp>
    self[:] = [self._path_factory(p) for p in text.split(self._pathsep)]
  File "/usr/lib/python3.5/site-packages/plumbum/machines/remote.py", line 202, in path
    p = self.env.expanduser(p)
AttributeError: 'SshMachine' object has no attribute 'env'

The error occurs on creation of the SshMachine:

with SshMachine("host", user="user") as rem:
    pass

It can be easily reproduced when you put some path with ~ into the PATH environment variable on the remote host:

export PATH=$PATH":~/bin:"

I used pyhon 3.5.2 with plumbum 1.6.2

@rrei
Copy link
Contributor

rrei commented Sep 21, 2017

This happens with ParamikoMachine as well.
I'm using plumbum 1.6.3 on python 3.6.2.

This is a blocker for me, because I am developing something that cannot assume control of the environment on the remote host.

Can I submit a pull request with a fix for this?
I've taken a look at the code and it seems that this can be fixed easily (plumbum/machines/remote.py:202) by calling a _expanduser() method on the remote machine itself if its RemoteEnv is not yet present. The code on RemoteEnv.expanduser() would be moved to BaseRemoteMachine._expanduser() and simply call this method on the remote.

Since this fixes the problem on the base classes, SshMachine would be fixed as well :)

@henryiii
Copy link
Collaborator

Sure, that would be great!

@rrei
Copy link
Contributor

rrei commented Sep 21, 2017

Here it is ;) #347

The travis build seems to be failing in some versions of Python, but I suspect that was already happening before :\

henryiii added a commit that referenced this issue Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants