小编Jed*_*tep的帖子

将PILLOW图像转换为StringIO

我正在编写一个程序,可以接收各种常见图像格式的图像,但需要以一致的格式检查它们.什么图像格式并不重要,主要是因为它们都是相同的.由于我需要转换图像格式然后继续使用图像,我不想将其保存到磁盘; 只需将其转换并继续.这是我使用StringIO的尝试:

image = Image.open(cStringIO.StringIO(raw_image)).convert("RGB")
cimage = cStringIO.StringIO() # create a StringIO buffer to receive the converted image
image.save(cimage, format="BMP") # reformat the image into the cimage buffer
cimage = Image.open(cimage)
Run Code Online (Sandbox Code Playgroud)

它返回以下错误:

Traceback (most recent call last):
  File "server.py", line 77, in <module>
    s.listen_forever()
  File "server.py", line 47, in listen_forever
    asdf = self.matcher.get_asdf(data)
  File "/Users/jedestep/dev/hitch-py/hitchhiker/matcher.py", line 26, in get_asdf
    cimage = Image.open(cimage)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 2256, in open
    % (filename if filename else fp))
IOError: cannot identify image file <cStringIO.StringO …
Run Code Online (Sandbox Code Playgroud)

python python-2.x stringio python-imaging-library

8
推荐指数
1
解决办法
7367
查看次数

如何让一个Flask应用在两个不同的端口上监听?

是否可以使用一个烧瓶应用程序在两个不同端口上路由?我的Flask应用程序需要侦听Webhook,并且由于一些安全事务,它无法在默认端口上接收外部POST请求。有可能做这样的事情吗?

@app.route('/hook/<sourcename>', methods=["POST"], port=5051)
def handle_hook(sourcename):
  print 'asdf'
Run Code Online (Sandbox Code Playgroud)

python flask

5
推荐指数
2
解决办法
5651
查看次数