类型错误:预期的字节数,找到 str [while running 'Writing to DB/ParDo(_WriteToRelationalDBFn),同时使用beam-nuggets写入数据库

问题描述

@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:预期字节,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```

解决方法

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

,

这个好像跟pg8000的版本有关。试试pip install pg8000==1.16.5。看起来像是在 1.16.6 中引入了重大更改。可在此处找到更多详细信息:https://github.com/sqlalchemy/sqlalchemy/issues/5645

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...