如何在Python套接字中接收和保存HTTP post请求中的图像?

如何在Python套接字中接收和保存HTTP post请求中的图像?,python,sockets,python-2.7,Python,Sockets,Python 2.7,我是python Socket的新手,我需要使用来自客户端的POST请求发送一个图像,并将图像保存在服务器上 我想我已经为客户做了正确的准备,但我不确定 这是我的客户代码: import httplib def printText(txt): lines = txt.split('\n') for line in lines: print line.strip() httpServ = httplib.HTTPConnection("127.0.0.1", 8

我是python Socket的新手,我需要使用来自客户端的POST请求发送一个图像,并将图像保存在服务器上

我想我已经为客户做了正确的准备,但我不确定

这是我的客户代码:

import httplib

def printText(txt):
    lines = txt.split('\n')
    for line in lines:
        print line.strip()

httpServ = httplib.HTTPConnection("127.0.0.1", 80)

httpServ.connect()



var = raw_input("Please enter a path of an image: ")

image = open(var, 'rb')
image_data = image.read()
image.close()

httpServ.request('POST', '/uplaod', image_data)


response = httpServ.getresponse()
if response.status == httplib.OK:
    print "Output from CGI request"
    printText(response.read())

httpServ.close()

我的问题是如何在服务器端接收该映像,以及如何将接收到的映像保存到某个路径。

我个人在创建quick-n-dirty web服务时使用瓶子库。比如:

import bottle

app=bottle.app()

@app.post('/upload')
def doUpload():
    upload      = request.files['upload']
    upload.save('filename')

app.run()
显然,这将不得不根据您的托管要求进行调整