Getting Errno 13: Permission Denied as a root user - python

So basically, I just want to load chess engine which is in the same folder with script
_, engine = await chess.engine.popen_uci('./engine')
What is wrong with this? I am running the script as a root user.
Also, if I load from just 'engine', it says file doesn't exist.
UPT: getting this error
_, self.engine = await chess.engine.popen_uci(r'' + os.path.join(os.getcwd(), 'engine'))
File "/usr/local/lib/python3.8/dist-packages/chess/engine.py", line 2642, in popen_uci
transport, protocol = await UciProtocol.popen(command, setpgrp=setpgrp, **popen_args)
File "/usr/local/lib/python3.8/dist-packages/chess/engine.py", line 1214, in popen
return await asyncio.get_running_loop().subprocess_exec(cls, *command, **popen_args) # type: ignore
File "/usr/lib/python3.8/asyncio/base_events.py", line 1630, in subprocess_exec
transport = await self._make_subprocess_transport(
File "/usr/lib/python3.8/asyncio/unix_events.py", line 197, in _make_subprocess_transport
transp = _UnixSubprocessTransport(self, protocol, args, shell,
File "/usr/lib/python3.8/asyncio/base_subprocess.py", line 36, in __init__
self._start(args=args, shell=shell, stdin=stdin, stdout=stdout,
File "/usr/lib/python3.8/asyncio/unix_events.py", line 789, in _start
self._proc = subprocess.Popen(
File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/root/ChessBot/engine'```

If we check documentation, in the playing section, you can see that the paths are assigned from the root like this:
r"C:\Users\xxxxx\Downloads\stockfish_14_win_x64\stockfish_14_win_x64_avx2.exe"
or "/usr/bin/stockfish".
Although the engine you want to use is in the same folder where you run the program, the path may be obtained directly from the path where Python is installed, I would recommend using _, engine = await chess.engine.popen_uci(r''+os.path.join(os.getcwd(), 'engine')) instead.

Resolved this by myself now. Need to execute this on engine file
$ chmod 755 engine
So basically, it changes files permissions to the required ones.

Related

Can't upload file to sftp server with Paramiko Python [duplicate]

This question already has an answer here:
Uploading file via Paramiko SFTP not working
(1 answer)
Closed 2 years ago.
I want to upload a file to a SFTP server using Paramiko, but I don't seem to get it right.
I thought I got the respective error cause of the file path '/' witch is the root on the server but I didn't get anywhare.
I keep getting this error:
File "c:\python\whitelistBot\whitelistBot.py", line 63, in on_message
sftp_client.put('C:/python/whitelistBot/whitelist1.json', '/')
File "C:\python\whitelistBot\lib\site-packages\paramiko\sftp_client.py", line 759, in put
return self.putfo(fl, remotepath, file_size, callback, confirm)
File "C:\python\whitelistBot\lib\site-packages\paramiko\sftp_client.py", line 714, in putfo
with self.file(remotepath, "wb") as fr:
File "C:\python\whitelistBot\lib\site-packages\paramiko\sftp_client.py", line 372, in open
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
File "C:\python\whitelistBot\lib\site-packages\paramiko\sftp_client.py", line 813, in _request
return self._read_response(num)
File "C:\python\whitelistBot\lib\site-packages\paramiko\sftp_client.py", line 865, in _read_response
self._convert_status(msg)
File "C:\python\whitelistBot\lib\site-packages\paramiko\sftp_client.py", line 898, in _convert_status
raise IOError(text)
OSError: Operation Unsupported
The code I'm running:
import paramiko
FTP_HOST = "********"
FTP_USER = "********"
FTP_PASS = "********"
FTP_PORT = ****
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname= FTP_HOST, username=FTP_USER, password=FTP_PASS, port=FTP_PORT)
sftp_client = ssh_client.open_sftp()
sftp_client.put('C:/python/whitelistBot/whitelist1.json', '/')
sftp_client.close()
ssh_client.close()
EDIT: I changed the directory where to put the file to "/home/container" cause that's what they told me in the site but except for the fact that I don't get that error message, the file does not appear on the server
Looks like I had to specify the name of the file '/whitelist1.json' like so:
sftp_client.put('C:/python/whitelistBot/whitelist1.json', '/whitelist1.json') # don't know why but yeah

builtins.OSError: 'git' has an invalid shebang line: 'git' is not a valid executable

I'm a new beginner on buildbot. I setup the master.cfg according to the guild of Buildbot 1.5.0 documentation.
I’ve setup master by the guild of Tutorial. The master.cfg is master.cfg.sample. It can be forced to build and the result is success. But there was an error in twistd.log.
builtins.OSError: 'git' has an invalid shebang line: 'git' is not a valid executable
Please see following for more details.
Could any tell me what happened? I'm sure git is well installed because it can be forced to build successfully.
It can be forced to build successfully.
2019-03-01 11:45:32+0800 [-] while polling for changes
Traceback (most recent call last):
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\twisted\internet\defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\buildbot\changes\gitpoller.py", line 410, in _dovccmd
stdout = yield self._dovccmdImpl(command, args, path)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\twisted\internet\defer.py", line 1613, in unwindGenerator
return _cancellableInlineCallbacks(gen)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\twisted\internet\defer.py", line 1529, in _cancellableInlineCallbacks
_inlineCallbacks(None, g, status)
--- <exception caught here> ---
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\buildbot\changes\gitpoller.py", line 192, in poll
yield self._checkGitFeatures()
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\buildbot\changes\gitpoller.py", line 122, in _checkGitFeatures
stdout = yield self._dovccmd('--version', [])
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\buildbot\changes\gitpoller.py", line 410, in _dovccmd
stdout = yield self._dovccmdImpl(command, args, path)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\twisted\internet\defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\buildbot\changes\gitpoller.py", line 434, in _dovccmdImpl
full_args, path=path, env=full_env)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\twisted\internet\utils.py", line 174, in getProcessOutputAndValue
reactor)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\twisted\internet\utils.py", line 28, in _callProtocolWithDeferred
reactor.spawnProcess(p, executable, (executable,)+tuple(args), env, path)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\twisted\internet\posixbase.py", line 353, in spawnProcess
return Process(self, processProtocol, executable, args, env, path)
File "c:\buildbot\tmp\bb-master\sandbox\lib\site-packages\twisted\internet\_dumbwin32proc.py", line 240, in __init__
command, command))
builtins.OSError: 'git' has an invalid shebang line: 'git' is not a valid executable
You can see the kind of code producing the error message here:
# look for a shebang line. Insert the original 'command'
# (actually a script) into the new arguments list.
sheb = _findShebang(command)
if sheb is None:
raise OSError(
"%r is neither a Windows executable, "
"nor a script with a shebang line" % command)
else:
args = list(args)
args.insert(0, command)
cmdline = quoteArguments(args)
origcmd = command
command = sheb
try:
# Let's try again.
doCreate()
except pywintypes.error, pwte2:
# d'oh, failed again!
if _invalidWin32App(pwte2):
raise OSError(
"%r has an invalid shebang line: "
"%r is not a valid executable" % (
origcmd, sheb))
raise OSError(pwte2)
So apparently, when executing git (as extracted from a shebang), the process does not find git in the path, and fails.
Using /c/path/to/git.exe as a shebang might be more productive.

Using Python Subprocess to send command lines to command prompt [Error 2: The system cannot find the file specified]

I'm trying to send a command line to command prompt (terminal) and read the output but I keep receiving the error:
self get_version(self)
File <folder path of my script>, line 39, in get_version
stdout = subprocess.PIPE
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Here's my code:
import subprocess
def get_version(self)
command = "wmic datafile where name='c:\\Drivers\\current_version\\GenericDriverSetup.exe' get version"
proc = subprocess.Popen([command],
stdout=subprocess.PIPE)
stdout_value = proc.communicate()[0]
print '\tstdout:', repr(stdout_value)
Can someone tell me what's wrong with this? Thanks so much

Python SSH Commands

I have the following code :
def executeRemoteCommand(host, command):
cmd = "ssh " + host + " \'" + command + "\'"
print cmd
subprocess.check_call(cmd)
When I run the command:
java -Xss515m -Xms48g -Xmx48g -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -jar /local/experiments/helloworld/ro/server.jar /local/experiments/helloworld/ro/properties.json
using the function above, I get the following error
File "./util/ssh_util.py", line 85, in executeRemoteCommand
subprocess.check_call(cmd)
File "/usr/lib/python2.7/subprocess.py", line 506, in check_call
retcode = call(*popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory.
However, when I type in the call directly in the command line, it works fine.
ssh foo92 'java -Xss515m -Xms48g -Xmx48g -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -jar /local/experiments/helloworld/ro/server.jar /local/experiments/helloworld/ro/properties.json'
Does anyone have any idea?
You need to set shell=True to execute that command through a shell:
subprocess.check_call(cmd, shell=True)
Rather than push this through a shell, you can execute it directly if you pass in the arguments as a list; that way you don't have to worry about quoting the command either:
def executeRemoteCommand(host, command):
subprocess.check_call(['ssh', host, command])
Note that both host and command here are single arguments passed to ssh. Normally, that is how the shell would pass the arguments into the ssh command, that's what the quoting around the java ... command line is for.

'put' in SFTP using Paramiko

I've installed and written the following Paramiko which is unable to put the file. It is easily able to 'get' a file and execute ls commands on it.
#set username & password
username='runaway'
password='runaway'
port=22
source= '/Unzip.sh'
destination ='/var/mpx/www/http'
#SFTP
client.load_system_host_keys()
print " hostname =%s \n username=%s \n password=%s \n" (hostname,username,password)
t = paramiko.Transport((hostname, port))
t.connect(username=username,password=password)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(source,destination)
#sftp.close()
#t.close()
Using a 'put' command gives the following error & stack trace -
File "upload_file.py", line 84, in ?
sftp.put(source,destination)
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 522, in put
fr = self.file(remotepath, 'wb')
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 221, in open
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 572, in _request
return self._read_response(num)
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 619, in _read_response
self._convert_status(msg)
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 649, in _convert_status
raise IOError(text)
IOError: Failure
How do I overcome this?
The solution seemed very funny to me!
source= '/Unzip.sh'
destination ='/var/mpx/www/http/Unzip.sh'
Just modified the destination path to include the file name as well.
Didn't expect some error like this coming from a Python package.
This also occurs in 2.0.2 when you try to sftp.mkdir('/exists'):
Traceback (most recent call last):
...
File "/usr/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 380, in mkdir
self._request(CMD_MKDIR, path, attr)
File "/usr/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 730, in _request
return self._read_response(num)
File "/usr/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 781, in _read_response
self._convert_status(msg)
File "/usr/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 811, in _convert_status
raise IOError(text)
IOError: Failure
This was my Python 2.7.9 fix:
try:
sftp.mkdir(remote_dir)
except IOError:
logging.debug('%s already exists.', remote_dir)

Categories