# pick up the file which needs to be processed
current_file = file_names[0]
print "Processing current file: " + current_file
key = bucket.get_key(current_file)
print "Processing key: " + str(key)
key.get_contents_to_filename(working_dir + "test_stats_temp.dat")
print "Current directory: ",outputdir
print "File to process:",current_file
Processing test output for: ds=2013-08-27
Processing current file: output/test_count_day/ds=2013-08-27/task_201308270934_0003_r_000000
Processing key: Key: hadoop.test.com,output/test_count_day/ds=2013-08-27/task_201308270934_0003_r_000000
Traceback (most recent call last):
File "queue_consumer.py", line 493, in <module>
test_process.load_test_cnv_stats_daily(datestring,working_dir,mysqlconn,s3_conn,test_output_bucket,test_output)
File "/home/sbr/aaa/test_process.py", line 46, in load_test_cnv_stats_daily
key.get_contents_to_filename(working_dir + "test_stats_temp.dat")
File "/usr/lib/python2.7/dist-packages/boto/s3/key.py", line 1275, in get_contents_to_filename
fp = open(filename, 'wb')
IOError: [Errno 2] No such file or directory: '/home/sbr/aaa/test_stats_temp.dat'
I got this error, when I fetched data to DB from S3 output. I'm confused here. How to handle this issue?
The error:
IOError: [Errno 2] No such file or directory: '/home/sbr/aaa/test_stats_temp.dat'
Indicates that the path set with working_dir does not exist. Creating the directory will fix it.
Related
I have code in Pyhton(2.7) on a beagle bone black to create folders that I copy fills of data to. These folders are mounted to the micro-Sd card(archive) and a thumb drive(live data copy). The file is being made in my working dir.
Code:
#staticmethod # Creates a folder if not present
def create_folder(folder_name):
directory = os.path.dirname(folder_name)
try:
os.path.exists(directory)
print("Folder failed")
except:
os.makedirs(directory, 0o777)
print("Folder created")
Error:
Traceback (most recent call last):
File "/var/lib/cloud9/TEMS_Operations/System_Files.py", line 125, in <module>
temp.create_folder(temp.main_folder)
File "/var/lib/cloud9/TEMS_Operations/System_Files.py", line 41, in create_folder
directory = os.path.dirname(folder_name)
File "/usr/lib/python2.7/posixpath.py", line 122, in dirname
i = p.rfind('/') + 1
AttributeError: 'function' object has no attribute 'rfind'
Any Suggestions?
Test program:
def test(self): # System file test
name1 = self.alarm_file()
print(name1)
name2 = self.data_file()
print(name2)
name3 = self.main_folder()
print(name3)
name4 = self.arch_folder()
print(name4)
self.create_data_file(name2)
self.create_alarm_file(name1)
self.create_folder(name3)
self.create_folder(name4)
file_to = name3 + name1
file_from = mane4 +name1
self.copyfile(file_from, file_to)
temp = SystemFiles("ZapOFS", "ZapLab")
print(os.getcwd())
temp.test()
Errors:
/media/mmc/2019/1
/media/usb/2019/1
File created
File created
<type 'str'>
Folder failed
<type 'str'>
Folder failed
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/ikpdb.py", line 1866, in main
ikpdb._runscript(mainpyfile)
File "/usr/local/lib/python2.7/dist-packages/ikpdb.py", line 1415, in _runscript
exec(statement, globals, locals)
File "<string>", line 1, in <module>
File "/var/lib/cloud9/TEMS_Operations/System_Files.py", line 132, in <module>
temp.test()
File "/var/lib/cloud9/TEMS_Operations/System_Files.py", line 127, in test
copyfile(file_from, file_to)
File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: '/media/usb/2019/1ZapOFS_ZapLab_Alarm_File_2019_1.csv'
[IKPdb-g] 16:34:52,604104 - INFO - Uncaught exception. Entering post mortem debugging
The only way to allow the creation of folders in python on the mounted MMC and/or USB drives on the BeagleBone black is to remove the sudo password for the current users and add -rw permissions for the program.
# sudo echo "debian ALL=NOPASSWD: ALL" >>/etc/sudoers
Not what I was hoping for, but the only way i can find.
https://elinux.org/Beagleboard:BeagleBoneBlack_Debian
how can I create a file in python if the filename contains '/'
url='https://www.udacity.com/cs101x/index.html'
f=open(url,'w')
f.write('123')
f.close()
above code produces an error as
Traceback (most recent call last):
File "9.py", line 2, in <module>
f=open(url,'w')
IOError: [Errno 22] invalid mode ('w') or filename:https://www.udacity.com/cs101x/index.html'
Use os.path.basename() to isolate the filename.
import os
url='https://www.udacity.com/cs101x/index.html'
filename = os.path.basename(url)
f=open(filename,'w')
f.write('123')
f.close()
This will create a file called index.html
I am struggling with file access - I have my python 2.7 here:
C:\Python27
I created a txt file data.txt
and I am trying to get the shell to read and print values from it. Location of data.txt is in the same folder (C:\Python27\data.txt)
Every time I got the same error msg:
Traceback (most recent call last):
File "C:/Python27/FileReader.py", line 1, in <module>
infile = open('data.txt', 'r') # Open the file for reading.
IOError: [Errno 2] No such file or directory: 'data'
You need to enter the full filename data.txt instead of data only:
infile = open('data.txt', 'r')
Can some one help me with this error! it seems like marmalade cant find the pilist.
Current Build: GCC ARM Release (Tue Nov 25 12:49:05 2014)
ERROR: exception occured in s3e_deploy
Traceback (most recent call last):
File "D:\Marmalade\7.4\s3e\bin\\..\..\s3e\deploy\main.py", line 594, in
main()
File "D:\Marmalade\7.4\s3e\bin\\..\..\s3e\deploy\main.py", line 568, in main
run()
File "D:\Marmalade\7.4\s3e\bin\\..\..\s3e\deploy\main.py", line 544, in run
do_action(settings)
File "D:\Marmalade\7.4\s3e\bin\\..\..\s3e\deploy\main.py", line 461, in do_action
deploy.deploy_to_folder(settings, myargs, False, True if options.copy_manifest else False)
File "e:\9f402e98\s3e\deploy\common.py", line 1668, in deploy_to_folder
File "e:\9f402e98\s3e\deploy\common.py", line 1563, in sign_and_embed
File "e:\9f402e98\s3e\deploy\plugins\iphone\iphone.py", line 435, in deploy_to_folder
File "D:\Marmalade\7.4\s3e\python\lib\shutil.py", line 208, in copytree
raise Error, errors
shutil.Error: [('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\CrumblingPlatform\\CrumblingPlatform.plist', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\CrumblingPlatform\\CrumblingPlatform.plist', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\CrumblingPlatform\\\\CrumblingPlatform.plist'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\CrumblingPlatform\\CrumblingPlatform.png', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\CrumblingPlatform\\CrumblingPlatform.png', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\CrumblingPlatform\\\\CrumblingPlatform.png'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\InvisibleBlocker\\InvisibleBlocker.plist', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\InvisibleBlocker\\InvisibleBlocker.plist', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\InvisibleBlocker\\\\InvisibleBlocker.plist'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\InvisibleBlocker\\InvisibleBlocker.png', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\InvisibleBlocker\\InvisibleBlocker.png', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\InvisibleBlocker\\\\InvisibleBlocker.png'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\InvisiblePlatform\\InvisiblePlatform.plist', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\InvisiblePlatform\\InvisiblePlatform.plist', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\InvisiblePlatform\\\\InvisiblePlatform.plist'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\InvisiblePlatform\\InvisiblePlatform.png', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\InvisiblePlatform\\InvisiblePlatform.png', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\InvisiblePlatform\\\\InvisiblePlatform.png'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\InvisibleWall\\invisibleWall.plist', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\InvisibleWall\\invisibleWall.plist', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\InvisibleWall\\\\invisibleWall.plist'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\PlatformCrumbling\\Left', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\PlatformCrumbling\\Left', "[Error 206] The filename or extension is too long: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\PlatformCrumbling\\\\Left'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\PlatformCrumbling\\Middle', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\PlatformCrumbling\\Middle', "[Error 206] The filename or extension is too long: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\PlatformCrumbling\\\\Middle'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\PlatformCrumbling\\Right', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\PlatformCrumbling\\Right', "[Error 206] The filename or extension is too long: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\PlatformCrumbling\\\\Right'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\PlatformSlippery\\Left', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\PlatformSlippery\\Left', "[Error 206] The filename or extension is too long: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\PlatformSlippery\\\\Left'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\PlatformSlippery\\Middle', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\PlatformSlippery\\Middle', "[Error 206] The filename or extension is too long: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\PlatformSlippery\\\\Middle'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\PlatformSlippery\\Right', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\PlatformSlippery\\Right', "[Error 206] The filename or extension is too long: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\PlatformSlippery\\\\Right'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\StandardPlatform\\StandardPlatform.plist', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\StandardPlatform\\StandardPlatform.plist', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\StandardPlatform\\\\StandardPlatform.plist'"), ('deployments\\default\\iphone\\release\\intermediate_files\\TexturePacker\\Sprites\\StandardPlatform\\StandardPlatform.png', u'deployments\\default\\iphone\\release\\intermediate_files\\gamercamp.app\\TexturePacker\\Sprites\\StandardPlatform\\StandardPlatform.png', "[Errno 2] No such file or directory: u'deployments\\\\default\\\\iphone\\\\release\\\\intermediate_files\\\\gamercamp.app\\\\TexturePacker\\\\Sprites\\\\StandardPlatform\\\\StandardPlatform.png'")]
Python function copytree() generation an exception. Maybe in your case it is too large length of file's path. Try move your project closer to the root directory of drive
I want to loop through the files present in Audio_files folder and check if it is raw file or wave file and put it in the respective directories.
Here is my code:
import shutil
import os
source = os.listdir("/home/GM/codec_implement/Audio_files/")
destination = "/home/GM/codec_implement/raw_files/"
destination2 = "/home/GM/codec_implement/raw_files/wave_files/"
for files in source:
if files.endswith(".wav"):
shutil.copy(files,destination)
elif files.endswith(".raw"):
shutil.copy(files,destination)
else:
print "Invalid format"
Please let me know where I am making mistake. Error i get is:
Traceback (most recent call last): File "./checkaudiofiles.py", line
12, in shutil.copy(files,destination) File
"/usr/lib/python2.7/shutil.py", line 119, in copy copyfile(src, dst)
File "/usr/lib/python2.7/shutil.py", line 82, in copyfile with
open(src, 'rb') as fsrc: IOError: [Errno 2] No such file or directory:
'test_sound.wav'
The error means that the test_sound.wav file is not on that directory. These file might be removed between the two proces or the os.listdir() and the shutil.copy() don't list the files the same way.