C
cerr
Hi,
I have a Python script that is executing an http POST to transfer a file from the client to the server. I have achieved this with below code:
from binascii import hexlify, unhexlify
from httplib import HTTPConnection, HTTPException
import os
import hashlib
import socket
import urllib2
import time
import subprocess
import MultipartPostHandler
def post_file(filename, data):
try:
wakeup()
socket.setdefaulttimeout(TIMEOUT)
#create multipartpost handler
opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
#set POST arguments
host = HOST
func = "post_file"
fname = filename
#assemble post URL
url = "http://{0}{1}".format(host, URI)
print "POSTING "+fname
#assemble multipart header
data = {"data":data,"f":func,"fname":filename}
#execute POST
response = opener.open(url, data, timeout=TIMEOUT)
#reads server return value
retval = response.read()
print retval
if "SUCCESS" in retval:
return 0
else:
print "RETVAL: "+retval
return 99
except Exception as e:
print "EXCEPTION time "+str(time.time())+" - "+str(e)
return 99
but my problem is, the data gets posted to the sever but arrives in the `$_REQUEST` array and I'm expected to post stuff so that it arrives in the `$_FILES` array (this is a LAMP server). How do I need to modify my code to deliver it correctly?
Thank you,
I have a Python script that is executing an http POST to transfer a file from the client to the server. I have achieved this with below code:
from binascii import hexlify, unhexlify
from httplib import HTTPConnection, HTTPException
import os
import hashlib
import socket
import urllib2
import time
import subprocess
import MultipartPostHandler
def post_file(filename, data):
try:
wakeup()
socket.setdefaulttimeout(TIMEOUT)
#create multipartpost handler
opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
#set POST arguments
host = HOST
func = "post_file"
fname = filename
#assemble post URL
url = "http://{0}{1}".format(host, URI)
print "POSTING "+fname
#assemble multipart header
data = {"data":data,"f":func,"fname":filename}
#execute POST
response = opener.open(url, data, timeout=TIMEOUT)
#reads server return value
retval = response.read()
print retval
if "SUCCESS" in retval:
return 0
else:
print "RETVAL: "+retval
return 99
except Exception as e:
print "EXCEPTION time "+str(time.time())+" - "+str(e)
return 99
but my problem is, the data gets posted to the sever but arrives in the `$_REQUEST` array and I'm expected to post stuff so that it arrives in the `$_FILES` array (this is a LAMP server). How do I need to modify my code to deliver it correctly?
Thank you,