Fabric put command gives fatal error: 'No such file' exception - python

I'm using Fabric 1.01, and in my fabfile I'm using the put command. The line is:
put('file.tar.gz', '~/file.tar.gz')
The server is in the env.hosts list. file.tar.gz is in the same directory as the fabfile, and i'm running the code from this directory.
When I run the code, it gets up to the point where it is running this put command. Just before failing the output is:
[uname#site.com] put: file.tar.gz -> ~/file.tar.gz
Fatal error: put() encountered an exception while uploading 'file.tar.gz'
Underlying exception message:
No such file
Anyone know where this is coming from? The file definitely exists on my local machine, and I've also tried the second put() argument as just '/server/path/to/' and I've tried using the absolute path of the file for the first put() argument, all to no avail.

I found this error message rather misleading. The message that is printed is:
Fatal error: put() encountered an exception while uploading 'local/path'
Underlying exception:
No such file
Which leads you to think the problem is that somehow Python isn't seeing the file at local/path. I'm not certain this is never the case, but both in the case of the original question and in my case, the issue had nothing to do with that, and instead the issue was that the remote folder couldn't be found. Since this command won't automatically create any folders in the path that it doesn't find, it fails when it can't find any of the remote folders in the remote path.
In my particular case, the issue was that I provided a path that I intended to be interpreted as absolute on a remote Linux system, but I left off the initial /.

Oops, I got lazy when anonymizing the question. My code contained a tilde:
put('file.tar.gz', '~/file.tar.gz')
Apparently Fabric did the tilde interpolation using the home directory of my local machine, not the server. After replacing the tilde with the explicit path on the server it works fine.

The error could be more descriptive indeed. I thought that the file I was trying to upload was not found, but actually the directory where I wanted to upload the file to did not exist. After creating the directory, the error was resolved for me.

Related

Unable to get a command executed in python

I am unable to run the following command
C:\Users\deepa>python ..\scrape.py
It gives me an error
python: can't open file 'C:\Users\scrape.py': [Errno 2] No such file or directory
I have already set environment variables to get python executed from any directory.
If you have set your environment variables then you don't need to pass the path of the file (which you are passing is incorrect) while running the code. Just you can mention file name and it will get executed.
python scrape.py
For your command:
C:\Users\deepa>python ..\scrape.py
The problem is not related to the python path, it's about the ..\scrape.py,
Please make sure this python script (scrape.py) is in the right place, I recommend you use absolute path instead of related path, for example:
C:\Users\deepa>python D:\test\test.py
D:\test\test.py is the absolute path of this python script (scrape.py), or you can drag this file into your terminal/cmd/PowerShell etc., you will see its absolute path.

How can I call a different python script that is stored on my network?

I have a TKinter script that lets the user choose from a list of existing scripts, input the variables that particular script requires, and then passes the variables to that script to be run. When all files are stored locally it goes off without a hitch. Once I tried to move it onto the network, so that colleagues can use it, it stopped executing the script.
There is no error message, just nothing happens. For troubleshooting simplicity I wrote a simple script that just calls a second script that prints "success", and the same issue happens where the simple scripts work locally, but not when stored on the network.
Script1.py:
import os
path=r'G:/files/Script2.py'
os.system(path)
Script2.py:
print("success")
No error messages, and if I try os.path.exists(path) it returns "True".
os.system(path) returns no errors even when the path is known to be incorrect.
If I do try open(path) for a path that is actually incorrect I get: FileNotFoundError: [Errno 2] No such file or directory.
I also tried setting path equal to the global drive name instead of G, using the IP address, changing the direction of the slashes, putting in double slashes after G:, and not using r''. Everything gives me the same result.
I also tried using path=os.getcwd()+"//Script2.py" since currently the files are all in the same folder on the network, again no success.
I am currently accessing the network through a VPN from home.
From googling I came up with these, but couldn't get a solution from them either:
Accessing a network folder through a python program
Using Python, how can I access a shared folder on windows network?
use a python3 or python keyword before
os.system("sudo python3 {}".format(path))
or:
os.system(f"sudo python3 {path}")

Packaged Python program for Mac will not run when downloaded

I have Python program that I packaged with py2app so that the program query_agent.py became query_agent.app. I have a Java program that launches query_agent.app with the following command:
open ./query_agent.app --args abs_path1 abs_path2
, where abs_path1 and abs_path2 are string arguments.
I put everything in a folder and when I launch the JAR that eventually launches query_agent.app, everything runs perfectly as expected.
So I zip this folder so I can distribute it to others. Before sending, I put the zip on a flash drive and unzip it on another Mac computer to test it. Again, the program works as expected even when unzipped.
However, when I send the zip as a message attachment in an email, or upload the zip to a file hosting site like MediaFire, the program no longer works when unzipped. When I unzip the downloaded zip file on any Mac computer, right-click and open, I get the message:
query_agent Error
When I open the console, it shows the cause of the error:
The STATS_FILE_LOCATION points to a file that I am trying to write to. This file is located at query_agent.app/Contents/Resources/resources. As a reminder, this works fine if I use the version of the zip before it was uploaded.
It appears that the main error is shown in the last line as
OSError: [Errno 30] Read-only file system: 'resources/status.txt'
The first thing I notice is that it is finding my source files in the /private/var/folder/... location. I believe this a temp location, which may be why I am getting the "read-only file system" error. I never intended for anything to be read from or written to any location outside of my main applications folder.
I also get the message:
Detected missing constraints for <private>. It cannot be placed because there are not enough constraints to fully define the size and origin. Add the missing constraints, or set translatesAutoresizingMaskIntoConstraints=YES and constraints will be generated for you. If this view is laid out manually on macOS 10.12 and later, you may choose to not call [super layout] from your override. Set a breakpoint on DETECTED_MISSING_CONSTRAINTS to debug. This error will only be logged once.
So my question is: Why doesn't my program work if I upload it, download it, unzip it, and then try to run it?
It works before the upload on any Mac computer I put it on, so the fact that it gets zipped is not the issue. I hope that these obscure error messages can provide some hints to why this is happening. Any help with solving this problem will be greatly appreciated.

Path issues installing load2neo

I've already parsed my data in a geoff .txt file.
I've downloaded the three files and I've put the two .jar files under
/Applications/Neo4j\Community\Edition.app/Contents/Resources/app/plugins
Since my server folder is located in a different directory, I've added the line:
org.neo4j.server.thirdparty_jaxrs_classes=com.nigelsmall.load2neo=/load2neo
to my configuration file that's at:
/Users/Lucas/Documents/Neo4j/testdb/neo4j.properties
When I try to start the server I get:
Starting Neo4j failed: Multiple exceptions
I'm pretty sure that I'm placing files in wrong locations and/or using wrong paths, but I don't have a clue on how to fix it.
Any help? Thanks!
There were two issues:
1.The path given on the configuration file was incorrect, in my case, the correct path was: org.neo4j.server.database.location=/Users/Lucas/Documents/Neo4j/testdb
2.I had another process using the port 7474. After I've changed the path to the correct value, the neo4j application gave me a error message about the port being used and I've killed the process with lsof -i :<port> and kill -9 <PID>
Hope it helps someone (:

Using Python subprocess from my web application to call an external script

I want to run a Python script "test.py" in my usr/local/bin directory, which will create a text file in the same directory and write some brief text to it.
This script is called by a Python subprocess in code that responds to a GET request to my web application, which resides at var/www
subprocess.Popen(["python", "usr/local/bin/test.py"])
The code runs without error, however the text file is not created. The code to to do this is straightforward:
myfile = open('test.txt','w+')
myfile.write("Write some text\n")
myfile.close()
I've tried passing options along with this including shell=True. As well, I've tried to use the interface provided by os.system(), also to no avail.
Just for testing purposes, I've given full permissions to all pertinent directories.
Running the test.py script via CLI works as intended, however not when called by the web application. What could be the issue?
There could be several reasons:
The current directory isn't what you expect. When you use subprocess.Popen() without specifying a current directory, the child inherits the current folder from the parent process. So it will run probably in the folder in which the web server was started.
Try an absolute path.
There is a / missing in your path: /usr/.... Without this, the script will again be search relative to the current directory.
You should really fix your error handling before you try to fix the other issues. You should have gotten a useful error message from the code above. If you didn't, then this is a very bad sign: It means that you won't notice if something breaks later.
At some time in the future, you will make a small change that will break something. Without good error handling, this will go unnoticed.

Categories