Python POST StringIO对象并使用PIL打开
当我使用StringIO发布图像加载,并使用web.py获取StringIO对象时,我无法使用PIL打开它。 我的邮政编码是:Python POST StringIO对象并使用PIL打开,python,python-imaging-library,web.py,stringio,Python,Python Imaging Library,Web.py,Stringio,当我使用StringIO发布图像加载,并使用web.py获取StringIO对象时,我无法使用PIL打开它。 我的邮政编码是: # encoding:utf-8 import requests from StringIO import StringIO img = open('test.jpg').read() img = StringIO(img) files = {'img': img} baseUrl = r'http://localhost:8080/test' requests.po
# encoding:utf-8
import requests
from StringIO import StringIO
img = open('test.jpg').read()
img = StringIO(img)
files = {'img': img}
baseUrl = r'http://localhost:8080/test'
requests.post(baseUrl, files = files)
My Web.py files index.py
import web
from PIL import Image
urls = ('/test', 'Test')
class Test:
def GET(self):
pass
def POST(self):
data = web.input()
# How: Use PIL to open the data?
img = Image.open(StringIO(data.img)) # report error
太棒了 解决了
POST文件应编写为:
# encoding:utf-8
import requests
from StringIO import StringIO
from PIL import Image
f = StringIO()
img = Image.open('test.jpg')
img.save(f, "JPEG")
f.seek(0)
files = {'img': f}
baseUrl = r'http://localhost:8080/test'
requests.post(baseUrl, files = files)