【问题标题】:Issue uploading and processing xls in Heroku using Python Flask [duplicate]使用 Python Flask 在 Heroku 中上传和处理 xls [重复]
【发布时间】:2018-11-15 01:07:37
【问题描述】:

我正在尝试在我的应用程序中上传 xls,然后在后端 iepython flask 中对其进行处理,以下代码在 ubuntu 14.04 中有效,但 在 Heroku 中失败 带有 Attribute错误 'Request' 对象没有属性 'get_array'

代码如下

import flask_excel as excel

try:
    if request.method == 'POST':
        file_obj = request.get_array(field_name='file')

heroku 中的错误是针对 request.get_array 'Request' object has no attribute 'get_array'

我在 heroku 中的 requirements.txt 有以下内容

Flask-Excel==0.0.7
pyexcel-xls==0.5.7

我的 HTML 代码如下

<form action="/upload_contacts" method="post" enctype="multipart/form-data">
   <input type="file" name="file">
   <button type="submit" class="btn btn-primary">Add Contacts</button>
</form>

我指的是这个http://flask-excel.readthedocs.io/en/latest/ 链接,用于上传 .xls/.xlsx 文件。
我确实尝试过寻找修复方法,在 github 中有人提到我必须使用 from flask.ext import excel 但这现在似乎已被弃用,取而代之的是 flask_excel。

请建议如何解决此问题。

谢谢

【问题讨论】:

  • 这段代码在 Ubuntu 14.04 上运行,但在 Heroku 上失败,
  • 我不明白为什么这个问题被关闭并指向一个没有帮助的问题,get_array 是特定于 Flask-excel 包的,只有在你安装它的情况下才可用

标签: python excel heroku file-upload flask


【解决方案1】:

也许你想使用request.argsit return MultiDict

request.args[<paramname>] get first find param, 

request.args.getlist(<paramname>) get a list

docs

【讨论】:

  • 我需要文件参数而不是列表/字典参数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-29
  • 1970-01-01
  • 2015-03-20
相关资源
最近更新 更多