【发布时间】:2018-01-26 07:06:33
【问题描述】:
我正在尝试处理 messenger-platform API (send-api-reference) 提供的这张图片
@app.route('/photobot/<path:photo_url>')
def tensor_photobot(photo_url):
file = cStringIO.StringIO(urllib.urlopen(photo_url).read())
img = Image.open(file)
if img:
list_elements = process_image(img)
return json.dumps(list_elements)
但图像无法识别。有什么想法吗?
消息:
{u'mid': u'mid.$cAAbv-uhIfdVkIn9OVld8TqA6u2Hz', u'seq': 40125, u'attachments': [{u'type': u'image', u'payload': {u'url': u'https://scontent-lht6-1.xx.fbcdn.net/v/t34.0-12/20916840_10214193209010537_198030613_n.jpg?_nc_ad=z-m&oh=3eab9a3a400c7e05fb5b74c391852426&oe=5998B9A8'}}]}
[参考][1] python 2.x
[1]: https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment
编辑:根据评论建议,我检测到问题来自 url-string 截断。
我添加了所有实现以获得更多上下文。
【问题讨论】:
-
你遇到了什么错误?
-
IOError: 无法识别图像文件
-
您是如何导入图像的?这似乎是一个常见错误,用户没有使用 Pillow,或者没有使用
from PIL import Image与import Image导入请参阅 this post。 -
我正在使用 from PIL import Image。如果我使用其他人的图片网址,但不使用 facebook-messenger 附件图片网址,则该过程非常有效。
-
您的代码在从 api 响应中提取查询字符串时是否有可能截断查询字符串?我能够很好地运行此代码,因此请尝试考虑可能的差异。
标签: image python-2.7 flask facebook-messenger facebook-messenger-bot