首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python水瓶Swagger Flasgger下载Excel

Python水瓶Swagger Flasgger下载Excel
EN

Stack Overflow用户
提问于 2016-06-30 09:22:46
回答 2查看 1.6K关注 0票数 1

我试图从Swagger返回一个excel文件。使用用Flasgger的Swagger包装器构建的。这是密码-

代码语言:javascript
复制
@app.route('/cluster', methods=['POST'])
def index():
    """
    This API will help you generate clusters based on keywords present in unstructured text
    Call this api passing the following parameters - 
        Dataset Path - <hostname>\\<path to dataset>
        Column Name based on which clustering needs to be done
        Number of Clusters
    Sample URL: http://localhost:8180/cluster/clusters.csv?dataset=\\\\W1400368\\c$\\Users\\VK046010\\Documents\\Python%20Scripts\\RevCycle_PatientAcc.csv&ext=csv&col=SR_SUM_TXT&no_of_clusters=100
    ---
    tags:
      - Clustering API
    parameters:
      - name: dataset
        in: formData
        type: file
        required: true
        description: The fully qualified path of the dataset without the extension.
      - name: col
        in: query
        type: string
        required: true
        description: The column name on which the clustering needs to be done
      - name: no_of_clusters
        in: query
        type: integer
        required: true
        description: The number of clusters
    """    
    global data      
    data = data.fillna('NULL')



output = StringIO.StringIO()
data.to_csv(output,index=False)

resp = Response(output.getvalue(), mimetype="text/csv")
resp.headers["Accept"] = "text/csv"
resp.headers['Access-Control-Allow-Origin'] = '*'
resp.headers["Content-Disposition"] = "attachment; filename=clusters.csv"
return resp

这将返回一个可下载的链接,我必须将该链接重命名为csv以使其工作。

问题:我不能对文件这样做。无论我如何做,一旦我下载和重命名,excel说文件是损坏的,这就是。

我试过pyexcel和熊猫出类拔萃的作家,但没有成功。请帮帮我!

EN

回答 2

Stack Overflow用户

发布于 2018-07-20 03:37:24

尝试使用flasgger下载excel。您可以将响应类型更改为“应用程序/八位元流”来解析它。

票数 1
EN

Stack Overflow用户

发布于 2016-06-30 13:02:10

你试过改变米制吗?

我认为excel的传统mimetype是application/vnd.ms-excel

您可以在这里找到有关microsoft文件mimetype的更多详细信息:What is a correct mime type for docx, pptx etc?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38118900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档