Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python POST StringIO对象并使用PIL打开_Python_Python Imaging Library_Web.py_Stringio - Fatal编程技术网

Python POST 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

当我使用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.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)