发送临时xlsx文件以通过Python Falcon下载

时间:2018-11-15 12:47:32

标签: javascript python reactjs falconframework

客户端发出一个 post请求,我应该用我收到的数据生成的 .xlsx文件对此作出响应。数据可以完美到达,我可以处理它,并且好像发送了 .xlsx文件,但是客户端无法处理它。我希望下载窗口弹出并下载文件,但没有任何反应。因为创建了文件内存中,所以我看不到问题是在前端还是在API上。

这是文件发送的部分:

excel_filename = name + '.xlsx'
output = BytesIO()
wb = xlsxwriter.Workbook(output, {'in_memory': True})
ws = wb.add_worksheet()
row = col = 0
for colName in columnNames:
  ws.write(row, col, colName)
  col += 1
for r in rowData:
  col = 0
  row += 1
  for cellValue in r:
    ws.write(row, col, cellValue)
    col += 1
wb.close()

xlsx_file = output.getvalue()

resp.set_header("Content-Disposition", "attachment; filename=\"%s\"" % excel_filename)
resp.data = xlsx_file

这是客户的要求:

this.client.post('/export-report-excel', { data })

我已经搜索了几天,但找不到能解决我问题的任何东西。

编辑: 控制台显示

  

错误:解析器无法解析响应

1 个答案:

答案 0 :(得分:0)

我认为您必须添加

import time
import random

enemyHealth = 100
healthValue = 100

while enemyHealth > 0 or healthValue> 0:
    print("A: Attack")
    time.sleep(.2)

    print("B: Skill")
    time.sleep(.2)

    print("C: Defend")
    time.sleep(.2)

    print("D: Rest")
    time.sleep(.2)

    print("E: Exit")
    time.sleep(.2)

    turn1 = input("Input: ")



    if turn1.lower() == "a" or turn1.lower() == "b" or turn1.lower() == "c" or turn1.lower() == "d":
      if turn1.lower() == "a":
        damaget1 = random.randint(1,5)
        print("You did " + str(damaget1) + " damage!")
        enemyHealth -= damaget1
        print("AI is now at " + str(enemyHealth) + " health.")

        damaget2 = random.randint(1,5)
        print("The bot did" + str(damaget2) + " damage!")
        healthValue -= damaget2
        print("You are now at " + str(healthValue) + " health!")

    if turn1.lower() == "e":
        break




print("Game Over")

标头,指示您的xlsx文件的mime类型