file upload via http

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Nov 18 19:42:32 EST 2002


>>>>> "Joost" == Joost van Rooij <joost_vanrooij.net at ace.bsd.uchicago.edu> writes:

  Joost>  import httplib

  Joost>  body = open("./image.jpg","r")
  Joost>  headers = {"Content-type": "multipart/form-data",

  Joost>  conn = httplib.HTTPConnection("www.server.net:80")
  Joost>  conn.request("POST", "/showme/picture/upload.php",body , headers)


Just a guess...

Does conn.request want a string or a file object for body.  You are
passing it a file object.  If it wants a string (and the help doesn't
specify), you should call

  conn.request("POST", "/showme/picture/upload.php",body.read(), headers)

Also, you may need to calculate the Content-Length field

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=3CBC9027.3010603%40nmt.edu&rnum=3&prev=/groups%3Fas_q%3D%2520HTTPConnection%2520request%2520post%26safe%3Dimages%26ie%3DUTF-8%26oe%3DUTF-8%26as_ugroup%3D*python*%26lr%3D%26hl%3Den


http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=mailman.982178415.9822.python-list%40python.org&rnum=3&prev=/groups%3Fq%3D%2BHTTPConnection%2Brequest%2B%2Bgroup%253A*python*%26btnG%3DGoogle%2BSearch%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8


John Hunter




More information about the Python-list mailing list