Why does Fabric throw 'TypeError: argument must be an int, or have a fileno() method'? - ssh

When running a Fabric task on a remote server I get the following stack trace:
[x.x.x.x] run: git fetch && git reset --hard origin/develop
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
self.run()
File "/var/lib/jenkins/jobs/deploy/workspace/.pyenv/lib/python2.6/site-packages/ssh/agent.py", line 115, in run
self._communicate()
File "/var/lib/jenkins/jobs/deploy/workspace/.pyenv/lib/python2.6/site-packages/ssh/agent.py", line 125, in _communicate
events = select([self._agent._conn, self.__inr], [], [], 0.5)
TypeError: argument must be an int, or have a fileno() method.
The fact that the Fabric task is trying to perform a git fetch and that exceptions is raised in ssh/agent.py makes me think something is wrong with SSH authentication.
The same user can run git fetch outside of Fabric, and the task runs fine on my laptop.
What's going on here? How do I resolve this issue?

An issue raised on Fabric's issue tracker mentions that the error might arise from not having ssh-agent running on the host.
I solved the problem by starting an ssh-agent and adding the user's key:
$> eval `ssh-agent`
$> ssh-add ~/.ssh/id_rsa
Success!

To auto-start ssh-agent when you first login, add this to your ~/.bashrc:
if [ ! -S ~/.ssh/ssh_auth_sock ]; then
eval `ssh-agent`
ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
ssh-add
fi
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock

I ran into this error while using Fabric with Python/Django when I was trying to execute tasks by hand within ./manage.py shell_plus.
It turns out (for me) that the error was caused by the fact that my shell_plus was set up to use bpython instead of ipython.
When I ran ./manage.py shell_plus --ipython instead, everything worked perfectly.
I realize that this probably wasn't a direct answer to your problem, but I figure I might as well leave a note here for anyone else who happens across the issue like I did.

Related

Crontab, Systemd.timer module import problem, Pyperclip could not find a copy/paste mechanism for your system

everyone i'm using oracle arm/amd processor servers with ubuntu 22.04
i have searching for an solution for this over 1 week more than 100 hours
but i had no luck to figure out what is the problem
so if you know about this please help me!
what is problem :
here's a simply code with pyperclip
import pyperclip
string = 'testing'
pyperclip.copy(string)
a = pyperclip.paste()
print()
whenever i execute this code directly in the cli , it is okay to run
However whenever i run this code with schedulers like Crontab or Systemd.timer
(xclip && xsel is already installed)
i got this error and cannot run the code like below
Traceback (most recent call last):
File "/home/ubuntu/web_selenium/pytest.py", line 10, in <module>
pyperclip.copy(string)
File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 689, in lazy_load_stub_copy
return copy(text)
File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 358, in __call__
raise PyperclipException(EXCEPT_MSG)
pyperclip.PyperclipException:
Pyperclip could not find a copy/paste mechanism for your system.
For more information, please visit https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error
i tried most of solutions in stackoverflow, mostly it was about setting path for interpreter and packages
of course i installed xclip and xsel as well / everything is good when i run code directly through cli
but only when i run code or shell script through Crontab , Systemd.timer, this error is generated
what i have tried
1. run pyperclip code through shell script with various python env PATH
i tried to lay all the possible env path like /usr/bin:/usr/local/bin .......
and even my python pakages path as .profile and ~./bashrc - failed
2. set new venv and install all the modules, run code - failed
3. run crontab as root - failed
4. install new ubuntu and switch server ubuntu amd -> ubuntu aarch64 - failed
5. reinstall module - failed
6. set shebang inside of python script ( whereis python3 - inside of python file - #!/usr/bin/python3.10) - failed
7. set shell into crontab (SHELL=/bin/bash) - failed
now i'm thinking this is the problem of pyperclip
pleaese help me!

problem trying to initiate a console with WSL 2 in CMDER

I have this error just trying to use WSL from cmder
wslbridge error: failed to start backend process
note: backend error output: -v: -c: line 0: unexpected EOF while looking for matchi ng `''
-v: -c: line 1: syntax error: unexpected end of file
ConEmuC: Root process was alive less than 10 sec, ExitCode=0.
Press Enter or Esc to close console...
does anyone how to solve it?
Create a new profile with the command wsl.exe.
Taken from https://github.com/Maximus5/ConEmu/issues/1930#issuecomment-512882561; it works for me.
For anybody having problems with this, I finally figured it out by setting a new task command of:
wsl.exe ~ -d Ubuntu-20.04
In my case, I had two versions of WSL installed and it wouldn't take the newer in Cmder for anything—it always loaded the ~ directory of my older install. You can use the file browser and go to directory \\wsl$ to see which version of WSL you are using.
I found this solution:
It is a ConEmu thing. The whole WSL part is for WSL version 1, I guess you are running WSL version 2?
You need a new version of cygwin1.dll
Grab one here: https://cygwin.com/snapshots/
Go to vendor\conemu-maximus5\ConEmu\wsl and replace the dll.
You need wslbridge 2:
Grab it here: https://github.com/Biswa96/wslbridge2/releases (the cygwin version)
Copy the content to the same directory: vendor\conemu-maximus5\ConEmu\wsl
Now edit your WSL bash task:
Replace the part "conemu-cyg-64.exe --wsl" with "conemu-cyg-64.exe %ConEmuBaseDirShort%\wsl\wslbridge2.exe"
It works now.

Setting {WSL::Bash} as default shell throws an error in cmder

note: backend error output: -v: -c: line 0: unexpected EOF while looking for matching `''
-v: -c: line 1: syntax error: unexpected end of file
ConEmuC: Root process was alive less than 10 sec, ExitCode=0.
Press Enter or Esc to close console...
This is error i am getting.
Also i have set the fish shell as default shell in WSL.
For WSL1 on windows 10 build later than 1909 (yes wsl2 is available to me but for corporate reasons i cant use it)
Try setting your command to wsl.exe -new_console:d:C:\_stuff\code -cur_console:p5 and the task parameters to /dir "c:/_stuff/code" /icon "c:/_distros/ubuntu/ubuntu1804.exe"
You may need to change the file locations to make the command and parameters suitable for your setup. c:/_stuff/code is where i keep all my repositories and c:/_distros/ubuntu is where i have installed ubuntu.

Getting "chmod(): Operation not permitted" on "composer update"

When I run 'composer update' I get this error:
Writing lock file
Generating autoload files
[ErrorException]
chmod(): Operation not permitted
*It works just fine with sudo, but then I have to reset the owner & permissions, Which is really annoying...
**I also tried to reset the owner of ~/.composer to www-data with 777, no effect.
***I'm using Ubuntu 16.04 LTS + Apache/2.4.18 & php7.0.26
Any idea?
chmod will only work without sudo if the owner of the file is the same as the one running the composer update command.
The problem is that the error message doesn't tell you which file it's trying to chmod.
This depends on the project.
Running the command in verbose mode will give you more details:
composer update -v
In my case, it gave me a stack trace, showing which file called chmod(), and the line number.
However, it didn't give me the path of the file passed to chmod().
I had to add a simple echo right before the call to chmod() (without forgetting to remove it afterwards).
Once you know which file/folder is responsible for the error message, change its owner with chown.
In my case (Magento 2.3), the culprit was the bin/magento file, which needs to be owned by the user running the composer commands.

I get an Input/Output error when trying to install a VOLTTRON agent

SSH into a VOLTTRON instance, installing agents works. Log out, log back in and installing results in the following error:
2016-09-13 11:46:24,409 () volttron.platform.vip.agent.subsystems.rpc ERROR: unhandled exception in JSON-RPC method 'install_agent':
Traceback (most recent call last):
File "/home/volttron/volttron/volttron/platform/vip/agent/subsystems/rpc.py", line 168, in method
return method(*args, **kwargs)
File "/home/volttron/volttron/volttron/platform/control.py", line 287, in install_agent
agent_uuid = self._aip.install_agent(path, vip_identity=vip_identity)
File "/home/volttron/volttron/volttron/platform/aip.py", line 296, in install_agent
unpack(agent_wheel, dest=agent_path)
File "/home/volttron/volttron/env/local/lib/python2.7/site-packages/wheel/tool/__init__.py", line 135, in unpack
sys.stderr.write("Unpacking to: %s\n" % (destination))
IOError: [Errno 5] Input/output error
When any background process is disowned, the ssh session is terminated, stdeff and stdout are not redirected to /dev/null, and the process tries to write to either it results in an IOError.
In this case one of the third party libraries that VOLLTRON uses when installing an agent tries to write to stderr (much to our chagrin). Even if the platform is run with the -l option it will still occasionally write to stderr. Unfortunately there is no reliable way for VOLTTRON to do the right thing with stderr in all cases so we have to leave it up to the user to know when they need to redirect output to /dev/null.
To run in the background use start-stop-daemon which automatically redirects everything to /dev/null or use this command to start the platform:
volttron -vv -l volttron.log > /dev/null 2>&1&
You can then safely disown the process and logout. Installations will still work.