import patoolib
patoolib.create_archive("file.zip", ("to_pdf.pdf"))
and on running i am getting the error
Traceback (most recent call last):
File "C:\Users\happy\Desktop\Site_Blocker\file_to_archive.py", line 2, in <module>
patoolib.create_archive("file.zip", ("to_pdf.pdf"))
File "C:\Users\happy\AppData\Local\Programs\Python\Python38\lib\site-packages\patoolib\__init__.py", line 712, in create_archive
util.check_archive_filelist(filenames)
File "C:\Users\happy\AppData\Local\Programs\Python\Python38\lib\site-packages\patoolib\util.py", line 422, in check_archive_filelist
check_existing_filename(filename, onlyfiles=False)
File "C:\Users\happy\AppData\Local\Programs\Python\Python38\lib\site-packages\patoolib\util.py", line 398, in check_existing_filename
raise PatoolError("file `%s' was not found" % filename)
patoolib.util.PatoolError: file `t' was not found
Please tell me how to fix this error.
The second argument of create_archive is the filenames. You appear to be trying to give it a tuple, which would work, but the syntax that you have used is not correct for creating a one-element tuple.
("to_pdf.pdf") will evaluate to simply "to_pdf.pdf", and when you iterate over this string you will get the characters in the string, hence the error on the first iteration that there is no file called t.
To create a one-element tuple, you should include the comma:
patoolib.create_archive("file.zip", ("to_pdf.pdf",))
Alternatively, you could use a list:
patoolib.create_archive("file.zip", ["to_pdf.pdf"])
Related
Does anyone have experience using the subprocess.call command in Python?
I keep getting errors whenever a line like this is in my code:
INFILE1 = open(script_dir+"/Scripts/plot_TSS_profile.R","r")
subprocess.call("Rscript","--slave","--args",filenames["housekeeping_profile"]+" "+filenames["unexpressed_profile"]+" "+filenames["profile_plot"],stdin=INFILE1, stderr=ERR_LOG,stdout=OUT_LOG,shell=True)
INFILE1.close().
If I leave the code as is, I get an error that the program finds multiple values for each th stdin, stderr, and stdout for some reason even though those are the only ones in the code. If I take out these parameters and just put the infile early in the brackets after “--args”, it doesn’t seem to read the file as it says the ‘buffer should be an integer.’
For example, this way gives the buffer error:
INFILE1 = script_dir+"/Scripts/plot_TSS_profile.R"
subprocess.call("Rscript",INFILE1,"--slave","--args",filenames["housekeeping_profile"]+" "+filenames["unexpressed_profile"]+" "+filenames["profile_plot"],stderr=ERR_LOG,shell=True)
INFILE1.close()
Here are my error outputs for more specific information:
The one on buffsize:
Traceback (most recent call last):
File "/mnt/work1/users/pughlab/projects/IEG_MiSEQ/Inferring_DNA_Expression/ExpressionPrediction-master/expression_prediction.py", line 277, in
step5(ERR_LOG,OUT_LOG,args,proj_dir,script_dir,filenames)
File "/mnt/work1/users/pughlab/projects/IEG_MiSEQ/Inferring_DNA_Expression/ExpressionPrediction-master/expression_prediction.py", line 165, in step5
subprocess.call("Rscript",INFILE1,"--slave","--args",filenames["housekeeping_profile"]+" "+filenames["unexpressed_profile"]+" "+filenames["profile_plot"],stderr=ERR_LOG,shell=True)
File "/mnt/work1/software/centos7/python/2.7.15/lib/python2.7/subprocess.py", line 172, in call
return Popen(*popenargs, **kwargs).wait()
File "/mnt/work1/software/centos7/python/2.7.15/lib/python2.7/subprocess.py", line 343, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
And the other error on there being multiple values:
Traceback (most recent call last):
File "/mnt/work1/users/pughlab/projects/IEG_MiSEQ/Inferring_DNA_Expression/ExpressionPrediction-master/expression_prediction.py", line 272, in <module>
step5(ERR_LOG,OUT_LOG,args,proj_dir,script_dir,filenames)
File "/mnt/work1/users/pughlab/projects/IEG_MiSEQ/Inferring_DNA_Expression/ExpressionPrediction-master/expression_prediction.py", line 165, in step5
subprocess.call("Rscript","--slave","--args",filenames["housekeeping_profile"]+" "+filenames["unexpressed_profile"]+" "+filenames["profile_plot"],stdin=INFILE1,stderr=ERR_LOG,stdout=OUT_LOG,shell=True)
File "/mnt/work1/software/centos7/python/2.7.15/lib/python2.7/subprocess.py", line 172, in call
return Popen(*popenargs, **kwargs).wait()
TypeError: __init__() got multiple values for keyword argument 'stdin'
Thank you
The main problem is that call takes a list of arguments or a single string to be parsed by the shell. You don't appear to need shell=True here; just create a single list of all the positional arguments you attempting to pass.
with open(script_dir+"/Scripts/plot_TSS_profile.R","r") as INFILE1:
cmd = [
"Rscript",
"--slave",
"--args",
filenames["housekeeping_profile"],
filenames["unexpressed_profile"],
filenames["profile_plot"]
]
subprocess.call(cmd, stdin=INFILE1, stderr=ERR_LOG, stdout=OUT_LOG)
Passing multiple positional arguments means that parameters that were meant to be set via keyword arguments (like stdin, etc) are being assigned values that were meant as part of the command to execute.
I'm trying to add keywords to the IPTC data in a JPG file and failing miserably. I'm able to read in the keywords using the iptcinfo3 library and, seemingly, append the keyword to the list of current keywords but I'm failing when trying to write those keywords back to the JPG file, if not sooner. The error message is a bit unclear to me and may actually reference the appending of the new keyword (although a print statement seems to indicate it took).
I've tried three different metadata libraries (there doesn't seem to be one standard) and this is the furthest I've gotten with any of them (failing to even install one and not being able to get a second one to run). This seems so basic but I can't figure it out and haven't been able to adapt the few other code examples I've seen online to work, including iptcinfo3's example code fragment.
The current Error message is:
| => pipenv run python editMetadata.py
WARNING: problems with charset recognition (b'\x1b')
[b'Gus']
[b'Gus', b'frog']
Traceback (most recent call last):
File "editMetadata.py", line 22, in <module>
info.save_as('Gus2.jpg')
File "/Users/Scott/.local/share/virtualenvs/editPhotoMetadata-tx0JAOmI/lib/python3.7/site-packages/iptcinfo3.py", line 635, in save_as
jpeg_parts = jpeg_collect_file_parts(fh)
File "/Users/Scott/.local/share/virtualenvs/editPhotoMetadata-tx0JAOmI/lib/python3.7/site-packages/iptcinfo3.py", line 324, in jpeg_collect_file_parts
adobeParts = collect_adobe_parts(partdata)
File "/Users/Scott/.local/share/virtualenvs/editPhotoMetadata-tx0JAOmI/lib/python3.7/site-packages/iptcinfo3.py", line 433, in collect_adobe_parts
out = [''.join(out)]
TypeError: sequence item 0: expected str instance, bytes found
Code:
from iptcinfo3 import IPTCInfo
import os
# Create new info object
info = IPTCInfo('Gus.jpg')
# Print list of keywords
print(info['keywords'])
# Append the keyword I want to add
info['keywords'].append(b'frog')
# Print to test keyword has been added
print(info['keywords'])
# Save new info to file
info.save()
info.save_as('Gus2.jpg')
Instead of appending use equal "="
from iptcinfo3 import IPTCInfo
info = IPTCInfo('Gus.jpg')
print(info['keywords'])
# add keyword
info['keywords'] = ['new keyword']
info.save()
info.save_as('Gus_2.jpg')
I have the same error. It seems to be an issue with the save depending on the file.
from iptcinfo3 import IPTCInfo
info = IPTCInfo('image.jpg', force=True)
info.save()
Which gives me the same error.
WARNING: problems with charset recognition (b'\x1b')
WARNING: problems with charset recognition (b'\x1b')
Traceback (most recent call last):
File "./searchimages.py", line 123, in <module>
main(sys.argv[1:])
File "./searchimages.py", line 119, in main
find_photos(str(sys.argv[1]))
File "./searchimages.py", line 46, in find_photos
write_keywords(image, current_keywords, new_keywords)
File "./searchimages.py", line 109, in write_keywords
info.save_as('out.jpg')
File "/usr/local/lib/python3.7/site-packages/iptcinfo3.py", line 635, in save_as
jpeg_parts = jpeg_collect_file_parts(fh)
File "/usr/local/lib/python3.7/site-packages/iptcinfo3.py", line 324, in jpeg_collect_file_parts
adobeParts = collect_adobe_parts(partdata)
File "/usr/local/lib/python3.7/site-packages/iptcinfo3.py", line 433, in collect_adobe_parts
out = [''.join(out)]
TypeError: sequence item 0: expected str instance, bytes found
I have a Python script obtained from a project which I am trying to debug however I am unable to resolve one error. Per the author's description of the project, everything works fine.
The script takes a parameter called "ascii" which is of type str as shown below:
parser.add_argument('--ascii', type=str,
help='ASCII Data type: ASCII characters')
Per my understanding, in the following code, it processes the input string one character at a time and each character is sent to a function, iter_bin() which will take the ASCII value of the character and convert it to binary, appending the output to a list.
ASCIIDATA = args.ascii
dataArray = []
for line in ASCIIDATA:
for entry in line:
# Make sure everything is a number, convert if not
dataArray.append(''.join(s for s in iter_bin(entry)))
def iter_bin(s):
sb = s.encode('ascii')
return (format(b, '07b') for b in sb)
When I run this code, I get the following error:
Traceback (most recent call last):
File "check.py", line 107, in <module>
main()
File "check.py", line 70, in main
dataArray.append(''.join(s for s in iter_bin(entry)))
File "check.py", line 70, in <genexpr>
dataArray.append(''.join(s for s in iter_bin(entry)))
File "check.py", line 82, in <genexpr>
return (format(b, '07b') for b in sb)
ValueError: Unknown format code 'b' for object of type 'str'
How can I resolve this error?
Thanks.
I am trying to use shutil.move but getting error as below:
Traceback (most recent call last):
File "packageTest.py", line 202, in <module>
writeResult()
File "packageTest.py", line 92, in writeResult
shutil.move(tempfile,'report.csv')
File "/usr/local/lib/python2.7/shutil.py", line 294, in move
os.rename(src, real_dst)
TypeError: coercing to Unicode: need string or buffer, instance found
I am new to python and not sure what is wrong in this. Can anybody help me in this? I checked even whether i am trying to open the file twice but it is not so.
def writeResult():
tempfile=NamedTemporaryFile(delete=False)
result='FAIL'
with open('report.csv','rb') as infile,tempfile:
csvreader=csv.DictReader(infile)
fieldnames=csvreader.fieldnames
csvwriter=csv.DictWriter(tempfile,fieldnames)
csvwriter.writeheader()
for node,row in enumerate(csvreader,1):
if(row['EXIST_IN_BOM']=='Yes'):
if(row['EXIST_IN_TAR']=='No'):
csvwriter.writerow(dict(row,RESULT='FAIL'))
csvwriter.writerow(dict(row,COMMENT='File is missing in package'))
else:
result='PASS'
else:
if(row['EXIST_IN_TAR']=='Yes'):
csvwriter.writerow(dict(row,RESULT='FAIL'))
csvwriter.writerow(dict(row,COMMENT='File is missing in BOM'))
if(row['SIZE_IN_TAR']==row['SIZE_IN_ALPHA']):
result='PASS'
else:
csvwriter.writerow(dict(row,RESULT='FAIL'))
csvwriter.writerow(dict(row,COMMENT='File size not same'))
if(result=='PASS'):
csvwriter.writerow(dict(row,RESULT='PASS'))
shutil.move(tempfile,'report.csv')
return
Edit: The below code works though:
tempfile=NamedTemporaryFile(delete=False)
with open('dict.csv','rb') as infile,tempfile:
csvreader=csv.DictReader(infile)
fieldnames=csvreader.fieldnames
csvwriter=csv.DictWriter(tempfile,fieldnames)
csvwriter.writeheader()
for node,row in enumerate(csvreader,1):
if(row['EmpId']=='119093'):
csvwriter.writerow(dict(row,Rank='1'))
if(row['EmpId']=='119094'):
csvwriter.writerow(dict(row,Rank='2'))
shutil.move(tempfile.name,'dict.csv')
shutil.move() takes two filenames, not a file-like and a filename. If you want to copy the contents of a file-like to a filename then open the filename in write mode and use shutil.copyfileobj() instead.
I am trying to run javascript with sublime text through nodejs plugin, and been getting the following message. I've found this question that seems to be relevant but I still couldn't figure it out. The script is encoded by UTF-8. Thank you.
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 532, in __bootstrap_inner
File "./lib/command_thread.py", line 41, in run
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 623, in __init__
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1141, in _execute_child
TypeError: execve() arg 3 contains a non-string value
ps. I am running OS X (10.8).
I had the same problem and it was fixed by putting this in my Nodejs.sublime-settings file (accessible by hitting command+shift+p and selecting Nodejs::User File Settings):
{
"node_path": "/opt/local/lib/",
"node_command": "/opt/local/bin/node"
}
Replace the paths with something that makes sense on your system.