在响应中发送图像时出错[FLASK]

2024-09-28 05:21:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我在服务器上有一个受Windows身份验证保护的图像文件,我必须访问该文件。 我使用python的requests\u ntlm模块通过Windows Auth访问该文件,我能够访问该文件。然而,在将这些数据作为图像发送回时,我得到了一个错误

我使用的示例代码如下所示:

def sendImage(imagename):
  """
  Takes image name as a parameter and get the file from the XYZ server 
  after Windows Authentication and serve the image as a response
  """
  
  username = USERNAME
  password = PASSWORD

  r = requests.get( BASE_URL + str(imagename), auth=HttpNtlmAuth(username, password))

  return send_file(
      io.BytesIO(r.content),
      mimetype='image/jpg'
  )

我得到的错误回溯如下:

Traceback (most recent call last):
  File "/home/pyenv/local/lib/python2.7/site-packages/werkzeug/wsgi.py", line 704, in __next__
    return self._next()
  File "/home/pyenv/local/lib/python2.7/site-packages/werkzeug/wrappers.py", line 81, in _iter_encoded
    for item in iterable:
TypeError: 'Response' object is not iterable

我已经检查过,当我将bytesIO的响应内容与PIL一起使用时,它是否被打开,因此我收到的图像存在问题

我无法找出这个错误的原因


Tags: and文件thein图像imagegetwindows

热门问题