You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Brightway2使用ExcelImporter调用write_database()时报错TypeError: keywords must be strings的求助

Fixing TypeError: keywords must be strings in bw2io ExcelImporter.write_database()

Hey there, let's work through this error you're facing. The traceback points directly to db.register(**self.metadata) in the bw2io code, which means the issue lies with non-string keys in your importer's metadata dictionary—Python requires keyword arguments (the **kwargs syntax) to have string keys.

Here are actionable steps to resolve this:

1. Inspect the metadata for non-string keys

First, print out your importer's metadata right before calling write_database() to identify problematic keys:

print(imp.metadata)

Look for any keys that aren't string types (like integers, floats, or even None). For example, a key like 123 instead of "123" would trigger this error.

2. Fix metadata keys manually

If you find non-string keys, convert all keys to strings before writing to the database:

# Convert all metadata keys to strings
imp.metadata = {str(key): value for key, value in imp.metadata.items()}

# Now try writing again
imp.write_database()

3. Verify Excel sheet metadata formatting

Even with the official example, double-check the Excel file's metadata-related sheet (usually named "Metadata" or similar):

  • Ensure all cells in the key column are formatted as text (not numbers or blank).
  • Make sure there are no empty rows or invalid entries in the metadata section that could be parsed as non-string keys.

4. Update bw2io to the latest version

This could be a known bug that's been fixed in newer releases. Upgrade the package using:

pip install --upgrade bw2io

After upgrading, retry the import and write process with the official example to see if the issue resolves.


内容的提问来源于stack exchange,提问作者JeanS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 15:22:32