0

@mohaseeb

我正在尝试下面的示例将数据从 pub\sub 写入 postgresql。将 pub\sub 数据写入 postgresql 时出现以下错误。“/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/result.py”,第 545 行,在 _colnames_from_description colname = description_decoder(colname) TypeError: expected bytes, str found [while running ‘Writing to DB /ParDo(_WriteToRelationalDBFn)-ptransform-74904']

你能帮忙修一下吗?

    months = p | "Reading month records" >> beam.Create([
        {'name': 'Jan', 'num': 1},
        {'name': 'Feb', 'num': 2},
    ])
    months | 'Writing to Sqlite table' >> relational_db.Write(
        source_config=relational_db.SourceConfiguration(
            drivername='sqlite',
            database='/tmp/months_db.sqlite',
            create_if_missing=True
        ),
        table_config=relational_db.TableConfiguration(
            name='months',
            create_if_missing=True```
4

2 回答 2

3

这似乎与pg8000的版本有关。试试pip install pg8000==1.16.5。看起来 1.16.6 中引入了一项重大更改。更多细节可以在这里找到:https ://github.com/sqlalchemy/sqlalchemy/issues/5645

于 2021-02-07T19:03:21.090 回答
0

很难_WriteToRelationalDBFn从您发布的代码片段中分辨出正在做什么,但我想您需要将记录列名称从 str 类型转换为字节,例如:column_name = column_name.encode()

于 2021-01-25T23:06:11.353 回答