#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?
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
Crazy... and if i use c:\, i get a 500 error.
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>
:)
> 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>
Now i need a script for uploading the files from MY pc and then use the
sendmail thingie. Any tips about that script?
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/
> 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>
> 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.
@ 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
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
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.
Gaz
Google "file upload cgi".
Gerard
About the topic name, yes, it's meaningless and its a shame. I fucked
it up when typing the title =P
Did you google 'python cgi file upload' yet? Several people have pointed
you to an answer that doesn't use FTP.