Discussion:
[Tutor] Type Error
richard kappler
2015-09-14 14:29:37 UTC
Permalink
Still working on my data feed script, if you'll recall from previous
emails, it reads incoming data and creates a name for image files based on
the incoming data in a test environment. below is a snippet of that code
that copies the next image in the pool renaming it as it copies, sends to
another machine via ftp, the closes the file and *** should then delete the
file *** but does not.

img = str(i) + '.jpg'
ID = device + '_' + timestamp + '_' + counter + '.jpg'
src = '/home/test/DataFeed/input/BOT/' + img
dst = '/home/test/DataFeed/output/BOT' + ID
shututil.copyfile(src, dst)
file = open(dst, 'rb')
sendBOT01.storbinary('STOR ' + ID, file)
file.close()
os.remove(file)


everything works except the os.remove(file) which gives the following error:

Traceback (most recent call last):
File "DataFeedBatch.py", line 104, in <module>
os.remove(file)
TypeError: coercing to Unicode: need string or buffer, file found

I don't understand the error
--
All internal models of the world are approximate. ~ Sebastian Thrun
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Zachary Ware
2015-09-14 14:40:33 UTC
Permalink
Post by richard kappler
File "DataFeedBatch.py", line 104, in <module>
os.remove(file)
TypeError: coercing to Unicode: need string or buffer, file found
I don't understand the error
os.remove() expects a filename, and you're passing it a 'file' object.
--
Zach
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Rohit kumar
2015-09-14 14:43:13 UTC
Permalink
Correct, The filename should be passed as string value.

Regards,
--
Rohit Kumar | Technical Lead
ZeOmega | Population Health Management Solutions
Improving Population Health One Person at a Time
Office: +91 80 4243 2000 (4067) | Mobile: +91 9342637703


-----Original Message-----
From: Tutor [mailto:tutor-bounces+rohitraj007=***@python.org] On
Behalf Of Zachary Ware
Sent: 14 September 2015 20:11
To: tutor
Subject: Re: [Tutor] Type Error
Post by richard kappler
File "DataFeedBatch.py", line 104, in <module>
os.remove(file)
TypeError: coercing to Unicode: need string or buffer, file found
I don't understand the error
os.remove() expects a filename, and you're passing it a 'file' object.
--
Zach
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
--
This e-mail message (including any attachments) may contain information
that is confidential, protected by the attorney-client or other applicable
privileges, or otherwise comprising non-public information. This message is
intended to be conveyed only to the designated recipient(s). If you have
any reason to believe you are not an intended recipient of this message,
please notify the sender by replying to this message and then deleting it
from your system. Any use, dissemination, distribution, or reproduction of
this message by unintended recipients is not authorized and may be unlawful.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Joel Goldstick
2015-09-14 14:46:26 UTC
Permalink
Post by richard kappler
Still working on my data feed script, if you'll recall from previous
emails, it reads incoming data and creates a name for image files based on
the incoming data in a test environment. below is a snippet of that code
that copies the next image in the pool renaming it as it copies, sends to
another machine via ftp, the closes the file and *** should then delete the
file *** but does not.
img = str(i) + '.jpg'
ID = device + '_' + timestamp + '_' + counter + '.jpg'
src = '/home/test/DataFeed/input/BOT/' + img
dst = '/home/test/DataFeed/output/BOT' + ID
shututil.copyfile(src, dst)
file = open(dst, 'rb')
sendBOT01.storbinary('STOR ' + ID, file)
file.close()
os.remove(file)
File "DataFeedBatch.py", line 104, in <module>
os.remove(file)
TypeError: coercing to Unicode: need string or buffer, file found
I don't understand the error
--
All internal models of the world are approximate. ~ Sebastian Thrun
I'm not sure if you want to remove src or dst, but whichever one you
want to remove, use the name, not the file object, eg:

os.remove(src)
_______________________________________________
Post by richard kappler
https://mail.python.org/mailman/listinfo/tutor
--
Joel Goldstick
http://joelgoldstick.com
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Loading...