【问题标题】:TypeError: expected bytes, str found [while running 'Writing to DB/ParDo(_WriteToRelationalDBFn) while writing to db from using beam-nuggetsTypeError: expected bytes, str found [while running 'Writing to DB/ParDo(_WriteToRelationalDBFn) while writing to db from using beam-nuggets
【发布时间】:2021-04-27 22:35:08
【问题描述】:

@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```

【问题讨论】:

    标签: python python-3.x google-cloud-platform apache-beam beam-sql


    【解决方案1】:

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

    【讨论】:

    • 这对我有用!谢谢
    【解决方案2】:

    从您发布的代码 sn-p 很难判断 _WriteToRelationalDBFn 在做什么,但我想您需要将记录列名称从 str 类型转换为字节,例如:column_name = column_name.encode()

    【讨论】:

    • 谢谢,我已经尝试使用编码的列名,我仍然面临同样的问题。
    • 在将记录写入谷歌云 postgresql 时,我也面临同样的 postgresql 问题。
    猜你喜欢
    • 2016-07-20
    • 1970-01-01
    • 1970-01-01
    • 2018-10-01
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-17
    相关资源
    最近更新 更多