Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

No

2 views
Skip to first unread message

Gaz

unread,
Feb 21, 2006, 10:08:10 AM2/21/06
to
Check this piece of code:

#now add an image part
part = writer.nextpart()
part.addheader('Content-Transfer-Encoding', 'base64')
body = part.startbody('image/jpeg')
base64.encode(open('c:\check.jpg', 'rb'), body)

I get the following error:

IOError: [Errno 2] No such file or directory: 'c:\\check.jpg'
args = (2, 'No such file or directory')
errno = 2
filename = r'c:\check.jpg'
strerror = 'No such file or directory'

Dont know why im getting such error, the file is there. Perhaps wrong
filetype? Wrong read mode?

Peter Hansen

unread,
Feb 21, 2006, 10:49:23 AM2/21/06
to pytho...@python.org

What does it show if you put "print os.listdir('c:/')" on the line
before the open? (You'll obviously need to import os first.)

-Peter

Gaz

unread,
Feb 21, 2006, 11:27:20 AM2/21/06
to
OSError: [Errno 2] No such file or directory: 'c:/'

args = (2, 'No such file or directory')
errno = 2
filename = 'c:/'

strerror = 'No such file or directory'

Crazy... and if i use c:\, i get a 500 error.

Fredrik Lundh

unread,
Feb 21, 2006, 12:17:25 PM2/21/06
to pytho...@python.org
"Gaz" wrote:

that's probably because "c:\" is a syntax error:

>>> "c:\"
File "<stdin>", line 1
"c:\"
^
SyntaxError: EOL while scanning single-quoted string

but since you're getting a "500 error" instead, it sure sounds like you
forgot to tell us *how* you're running your scripts... (server, platform,
python version, etc).

</F>

Gaz

unread,
Feb 21, 2006, 1:02:22 PM2/21/06
to
Im running it in my test site at F2o.org. Perhaps its server's fault
and not script's fault. I'll deal this issue at its forums.

:)

Fredrik Lundh

unread,
Feb 21, 2006, 1:16:29 PM2/21/06
to pytho...@python.org
"Gaz" wrote:

> Im running it in my test site at F2o.org. Perhaps its server's fault
> and not script's fault. I'll deal this issue at its forums.

according to their FAQ, they run Red Hat Enterprise Linux. I'm pretty
sure RHEL doesn't come with a C: drive...

</F>

Gaz

unread,
Feb 21, 2006, 2:58:17 PM2/21/06
to
Aye, but the file is in MY drive, not the server. Perhaps thats the
issue? I bet it's so... how should i deal with it? Perhaps should be a
script that uploads the files to the server and then emails it... i
believed this was handled using the root in my PC, but now i see this
is not correct.

Now i need a script for uploading the files from MY pc and then use the
sendmail thingie. Any tips about that script?

Steve Holden

unread,
Feb 21, 2006, 2:58:44 PM2/21/06
to pytho...@python.org
Fredrik Lundh wrote:
> that's probably because "c:\" is a syntax error:
>
>
>>>>"c:\"
>
> File "<stdin>", line 1
> "c:\"
> ^
> SyntaxError: EOL while scanning single-quoted string
>
> but since you're getting a "500 error" instead, it sure sounds like you
> forgot to tell us *how* you're running your scripts... (server, platform,
> python version, etc).
>
The 500 error's almost certainly because the script is failing before it
emits anything on standard output (I'm presuming that the syntax error
will appear on standard error, without having checked ...).

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Fredrik Lundh

unread,
Feb 22, 2006, 5:42:19 AM2/22/06
to pytho...@python.org
Gaz wrote:

> Aye, but the file is in MY drive, not the server. Perhaps thats the
> issue? I bet it's so... how should i deal with it? Perhaps should be a
> script that uploads the files to the server and then emails it...

assuming that the web server can read files on your local disk is perhaps
a bit too optimistic.

how did you upload your program to the server in the first place ?

any reason you cannot use the same approach to upload the image ?

</F>

Steven D'Aprano

unread,
Feb 22, 2006, 6:36:50 AM2/22/06
to
On Wed, 22 Feb 2006 11:42:19 +0100, Fredrik Lundh wrote:

> Gaz wrote:
>
>> Aye, but the file is in MY drive, not the server. Perhaps thats the
>> issue? I bet it's so... how should i deal with it? Perhaps should be a
>> script that uploads the files to the server and then emails it...
>
> assuming that the web server can read files on your local disk is perhaps
> a bit too optimistic.

Come on, Gaz is running Windows. Chances are *everyone* can read files on
his local disk.

*wink*


--
Steven.

Gaz

unread,
Feb 22, 2006, 9:47:25 AM2/22/06
to
@ Steven: LOL =P

@ Frederik: aye, i uploaded the script by FTP, but the idea of this
little program is to allow a technician on field to upload photos from
their laptops when they get into a hotel, along with some text, anywere
in the world. We need the reports to be daily. Email is not an option,
because due my experience, they always lack of info, with a form, i can
put some conditions for sending the report.

So, they can not upload the photos by FTP because its too "geek" for
them. And i need to have a standarized form to handle the reports,
because otherwise its a organizational mess.

The program should handle the upload thingie in the backstage. I'll
look for a script like this in these forums...

Kent Johnson

unread,
Feb 22, 2006, 10:20:31 AM2/22/06
to
google 'python cgi file upload' for many examples.

Kent

Sion Arrowsmith

unread,
Feb 22, 2006, 10:44:53 AM2/22/06
to
Gaz <gaz...@gmail.com> wrote:
>So, they can not upload the photos by FTP because its too "geek" for
>them. And i need to have a standarized form to handle the reports,
>because otherwise its a organizational mess.

Am I missing something here, or is all you need a
<INPUT TYPE="FILE" ... >
on your form? Then you don't worry about filenames, you just get
their data supplied to your cgi script.

--
\S -- si...@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

Gaz

unread,
Feb 22, 2006, 12:31:07 PM2/22/06
to
(the Input type = FILE is in the field)

please check this out

import ftplib
import os

...

def upload(ftp, file):
ext = os.path.splitext(file)[1]
if ext in (".txt", ".htm", ".html"):
ftp.storlines("STOR " + file, open(file))
else:
ftp.storbinary("STOR " + file, open(file, "rb"), 1024)

ftp = ftplib.FTP("ftp.XXXX.f2o.org")
ftp.login("XXXXX", "XXXXX")

upload(ftp, "c:\check.jpg")

I'm still getting the file not found error:

http://img153.imageshack.us/img153/2720/error3ps.jpg

I believe the path is kinda wrong or something. But this time, the
script is supposed to fetch the file from my pc.

Gerard Flanagan

unread,
Feb 22, 2006, 1:05:43 PM2/22/06
to

Gaz

Google "file upload cgi".

Gerard

Message has been deleted

Gaz

unread,
Feb 23, 2006, 8:40:45 AM2/23/06
to
Aye, but i dont need to run an FTP daemon every time i want to upload
an image to Imageshack or any other website.

About the topic name, yes, it's meaningless and its a shame. I fucked
it up when typing the title =P

Kent Johnson

unread,
Feb 23, 2006, 9:57:33 AM2/23/06
to
Gaz wrote:
> Aye, but i dont need to run an FTP daemon every time i want to upload
> an image to Imageshack or any other website.

Did you google 'python cgi file upload' yet? Several people have pointed
you to an answer that doesn't use FTP.

Gaz

unread,
Feb 23, 2006, 11:33:07 AM2/23/06
to
Yeah, i did. Thank you, im analyzing the examples found. I'll post my
results :)

Message has been deleted
Message has been deleted
0 new messages