TypeError:list索引必须是整数,而不是excel文件路径中的unicode,即xlrd.open_workbook

时间:2017-08-15 16:59:41

标签: python excel xlrd

我编写了一个程序,它创建一个excel表,从多个文件中获取数据并将它们添加到Excel工作表中。我必须再次进一步编辑这个工作表。

在这里,我正在尝试打开一个封闭的Excel工作簿。我正在使用xlrd.open_workbook来做到这一点。 这是一个错误: TypeError:list indices必须是整数,而不是unicode

def insertIntoTable(dtWithZone, tableName, columValues):
    db_uri = "postgresql://localhost/messages"
    engine = create_engine(db_uri, connect_args={"options": "-c timezone={}".format(dtWithZone.timetz().tzinfo.zone)})
    meta = MetaData(engine, reflect=True)
    table = meta.tables[tableName]
    ins = table.insert().values(**columValues)
    conn = engine.connect()
    conn.execute(ins)
    conn.close()

我得到的错误是: 回溯(最近一次调用最后一次):

@app.route('/newmsg', methods=['GET', 'POST'])
def newmsg():
    form = _appforms.MessagingForm()
    # if form.validate_on_submit():
    if request.method == "POST":
        ip = request.access_route[0]
        data = _utils.getJsonFromURL("http://ip-api.com/json/{}".format(ip))
        tz = "Pacific/America"
        if data["status"] == "success":
            tz = data.get("timezone")

        dtWithZone = datetime.datetime.now(pytz.timezone(tz))
        name = request.form.get('fullName', "")
        columValues = {
        'pub_date' : dtWithZone,  
        'fullName' : name,
        'visitorId': request.cookies.get("unique_visitor", ""),
        'message' : request.form.get('message', ""),
        'email' : request.form.get('email', "")
        }

        insertIntoTable(dtWithZone, 'messages', columValues)
        msg = "Thank you, {}".format(name)
        return render_template('thankyou.html', form=form, msg=msg)
    return render_template('newMessage.html', form=form, title=" | Messaging", msg="Write your message")

0 个答案:

没有答案