subprocess.check_output(('/Applications/googlecl-0.9.13/build/scripts-2.7/google', 'docs', 'get', r'"Reassessment Request"', r'--format', 'csv', r'/Users/myaccount/Desktop'), shell=True)
This code doesn't pull down the doc, but running the identical line will work inside Terminal. It might not be having time to complete? It takes a while when I run it from the command line.
There's a Python error:
"Traceback (most recent call last):
File "/Users/myaccount/Desktop/reassess2.py", line 17, in
subprocess.call('google docs get "Reassessment Request" --format csv /Users/myaccount/Desktop')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 679, in init
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory"
I get a similar problem when I try to run it in an OSX script:
When I run the shell script (running the command line above), I get:
?/Users/myaccount/Desktop/ReScript.sh ; exit;
.csvloading Reassessment Request to /users/myaccount/Desktop
logout
[Process completed]",
but no file is actually downloaded.
OSX Mountain Lion; 0.9.13 cl; 2.0.17 gdata (I think - not the most recent, but the one that works with cl)
Thanks for the help!
Google CL is pretty much on its way out, and the new form update to Google drive has broken it for these types of operations. I used Gdata as a workaround for a while, but if anyone is trying to use either of those and stumbles onto this, here's the best current answer: Gspread. It installs easily (unlike the others, which had tricky version compatibility issues), requires less code, and is faster.
With Gspread, this code would be replaced by:
username = 'jimjam#gmail.com'
password = 'bwdfsdfsafadlhsw'
sheetname = "Reassessment Requesttemp"
client = gspread.login(username, password)
spreadsheet = client.open(sheetname)
worksheet = spreadsheet.sheet1
contents = worksheet.get_all_values()
Related
I'm using this pydf to convert HTML to a PDF on our server. This is an example that comes right from their docs that illustrates the problem:
import pydf
pdf = pydf.generate_pdf('<h1>this is html</h1>')
with open('test_doc.pdf', 'wb') as f:
f.write(pdf)
When I go to run this file, I get the same error everytime:
(pdf) <computer>:<folder> <user>$ python pdf.py
Traceback (most recent call last):
File "pdf.py", line 3, in <module>
pdf = pydf.generate_pdf('<h1>this is html</h1>')
File "/Users/nilesbrandon/Projects/pdf/pdf/lib/python2.7/site-packages/pydf/wkhtmltopdf.py", line 121, in generate_pdf
return gen_pdf(html_file.name, cmd_args)
File "/Users/nilesbrandon/Projects/pdf/pdf/lib/python2.7/site-packages/pydf/wkhtmltopdf.py", line 105, in gen_pdf
_, stderr, returncode = execute_wk(*cmd_args)
File "/Users/nilesbrandon/Projects/pdf/pdf/lib/python2.7/site-packages/pydf/wkhtmltopdf.py", line 22, in execute_wk
p = subprocess.Popen(wk_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
I'm running this in a virtualenv and my pip freeze is only the following:
python-pdf==0.30
Any idea what could be going wrong here?
As you are using macOS, you need to download a wkhtmltopdf binary by your own:
pydf comes bundled with a wkhtmltopdf binary which will only work on Linux amd64 architectures. If you're on another OS or architecture your milage may vary, it is likely that you'll need to supply your own wkhtmltopdf binary and point pydf towards it by setting the WKHTMLTOPDF_PATH variable.
Let us consider Linux platform where I need to execute a program called smart.exe which uses input.dat file. Both the files are placed in the same directory with each file having the same file permission 777.
Now if I run the following command in the terminal window smart.exe is fully executed without any error.
$./smart.exe input.dat
On the other hand, if I use the following python script called my_script.py placed in the same directory, then I get an error.
my_script.py has the following code:
#!/usr/bin/python
import os, subprocess
exit_code = subprocess.call("./smart.exe input.dat", shell = False)
The error is as follows:
File "my_script.py", line 4, in <module>
exit_code = subprocess.call("./smart.exe input.dat", shell = False)
File "/usr/lib64/python2.6/subprocess.py", line 478, in call
p = Popen(*popenargs, **kwargs)
File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Can someone please tell me why this is happening. Please note that the smart.exe should take around 10 sec to fully complete. This may be a clue for the problem.
Please also advise if there is any other way to run smart.exe from my_script.py. Your solution is much appreciated!
You should decide if you want shell support or not.
If you want the shell to be used (which is not necessary here), you should use exit_code = subprocess.call("./smart.exe input.dat", shell=True). Then the shell interprets your command line.
If you don't want it (as you don't need it and want to avoid unnecessary complexity), you should do exit_code = subprocess.call(["./smart.exe", "input.dat"], shell=False).
(And there is no point naming your binarys .exe under Linux.)
I am trying to use this example script to test crontab in python:
from crontab import CronTab
tab = CronTab(user='www',fake_tab='True')
cmd = '/var/www/pjr-env/bin/python /var/www/PRJ/job.py'
cron_job = tab.new(cmd)
cron_job.minute().every(5)
#writes content to crontab
tab.write()
print tab.render()
It returns with an error 'fake_tab' not defined. If i remove this parameter and call the function
like this: CronTab(user='www'). I returns the following error :
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
tab = CronTab(user='www')
File "C:\Python27\lib\site-packages\crontab.py", line 160, in __init__
self.read(tabfile)
File "C:\Python27\lib\site-packages\crontab.py", line 183, in read
p = sp.Popen(self._read_execute(), stdout=sp.PIPE)
File "C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Does any one know, what am I missing?
I think that Crontab is a Unix/Linux concept. Not sure if it can work under windows. This Page says "Windows support works for manual crontabs only". Not sure what he means by that though.
As the author of python-crontab I can report that the documentation has been updated. It's clear ineffective given the number of people puzzled over what manual means.
If you do this:
mem_cron = CronTab(tab="""
* * * * * command # comment
""")
You should have a memory only crontab. Same if you do a file as a crontab:
file_cron = CronTab(tabfile='filename.tab')
I'm always looking to improve the code and documentation, so please do email me.
The easiest way I found to make crontab find my job was:
In settings.py (I'm using django) I defined these variables:
CRONTAB_EXECUTABLE='C:/Users/myuser/myvirtualenv/Lib/site-packages/django_crontab/crontab.py'
CRONTAB_DJANGO_PROJECT_NAME='myproject'
CRONTAB_DJANGO_MANAGE_PATH='C:/Users/myuser/myvirtualenv/myproject/manage.py'
CRONTAB_PYTHON_EXECUTABLE='C:/Users/myuser/AppData/Local/Programs/Python/Python36-32/pythonw.exe'
Pay attention to the slash. It must be leaned to the right or it causes a syntax error.
By this way crontab will find the job or whatever you are trying to execute. In my case I was trying:
C:\Users\bsi\mlearning3\src>python manage.py crontab add
In a python script, I issue the command:
def copy_file(csv_file): #csv_file = "wpa-01.csv"
subprocess.call(["cp",csv_file,"tempfile.csv"])
I get the error:
cp: cannot stat 'wpa-01.csv' : No such file or directory
-tempfile.csv is a valid file, it is open
-I have tried adding quotes around wpa-01.csv, ie
subprocess.call(["cp","\"wpa-01.csv\"","tempfile.csv"])
-I have tried adding escape character in front of the '-'
-I have tried including the directory in front og the file name
-I am using gedit on a local Linux machine (so its not a dos2unix kind of solution), but the script is being ran on a remote Raspberry Pi
in every case I get the same error. I am at a loss for solutions. any suggestions?
***Here is the problem: "wpa-01.csv" is a 'live'/'dynamic' file. There is an active process that is updating that file in real time. I think that the file will have to be 'dead'/'static' in order to issue cp command? This is not ideal for my purposes. Is there a way to work around this like changing the mod or something? If not I suppose I can try to find an alternative solution.
print "wpa-01.csv" in os.listdir(".") #make sure file really does exist
subprocess.call(["cp","\"wpa-01.csv\"","tempfile.csv"],shell=True)
My guess is you need to set shell=True so that it uses your path to find cp executes in your shell ... if you don't use shell=True it wont use your path ...
Unfortunately all it is is a guess ...
Anyway, here is some supporting evidence:
>>> subprocess.call("copy tmp5.py tmp55.py")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\subprocess.py", line 470, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python26\lib\subprocess.py", line 623, in __init__
errread, errwrite)
File "C:\Python26\lib\subprocess.py", line 833, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
>>> subprocess.call("copy tmp5.py tmp55.py",shell=True)
1 file(s) copied.
0
I have encountered an error which I am not able to resolve.
I am trying to perform the easiest set of commands that will perform a tBLASTn algorithm,
looking for a sequence (sequence specified as a "pytanie.fasta" file) in a database (also specified as file -> cucumber.fasta). The result will be saved in the "wynik.txt" file.
The code looks as following:
from Bio.Blast. Applications import NcbitblastnCommandline
database = r"\Biopython\cucumber.fasta"
qr = r"\Biopython\pytanie.fasta"
output = r"\Biopython\wynik.txt"
e = raw_input("Enter e-value: ")
tblastn_cline = NcbitblastnCommandline(cmd='blastn', db=database, query=qr, out=output, evalue=e, outfmt=7)
print tblastn_cline
stdout, stderr = tblastn_cline()
And the error I get:
File "C:\Users\IBM_ADMIN\Desktop\PYTHON\Workspace\Biopython\blast.py", line 20, in <module>
stdout, stderr = tblastn_cline()
File "C:\Python27\lib\site-packages\Bio\Application\__init__.py", line 435, in __call__
shell=(sys.platform!="win32"))
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
I am using:
Eclipse SDK Version: 3.7.1
Python version 2.7
OS: 64 bit Windows 7
I have tried this also on 32-bit Windows XP and it produces the same error.
Biopython package should work fine since it went through the tests suggested by biopython website. I have also tried other formats of the path where the files are located, but it did not work. My friend uses the same code on Ubuntu and it works fine.
Does anybody know how to fix this error?
What are the paths of the files?
The path r"\Biopython\cucumber.fasta", for example, is an absolute path on the current drive (because it starts with a backslash and no drive letter), which I think in your case is r"C:\Biopython\cucumber.fasta". Is that correct?