TypeError: expected bytes, str found [while running 'Writing to DB/ParDo(_WriteToRelationalDBFn) while writing to db from using beam-nuggets
TypeError: expected bytes, str found [while running 'Writing to DB/ParDo(_WriteToRelationalDBFn) while writing to db from using beam-nuggets
@mohaseeb
我正在尝试下面的例子,在将 pub\sub 数据写入 postgresql 时,将数据从 pub\sub 写入到 postgresql.Getting 以下错误。 “/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/result.py”,第 545 行,在 _colnames_from_description colname = description_decoder(colname) TypeError: 预期的字节数,str 找到 [while 运行 '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 类型转换为 bytes,例如:column_name = column_name.encode()
这好像和pg8000的版本有关。尝试 pip install pg8000==1.16.5
。看起来 1.16.6 中引入了重大更改。可以在此处找到更多详细信息:https://github.com/sqlalchemy/sqlalchemy/issues/5645
@mohaseeb
我正在尝试下面的例子,在将 pub\sub 数据写入 postgresql 时,将数据从 pub\sub 写入到 postgresql.Getting 以下错误。 “/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/result.py”,第 545 行,在 _colnames_from_description colname = description_decoder(colname) TypeError: 预期的字节数,str 找到 [while 运行 '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 类型转换为 bytes,例如:column_name = column_name.encode()
这好像和pg8000的版本有关。尝试 pip install pg8000==1.16.5
。看起来 1.16.6 中引入了重大更改。可以在此处找到更多详细信息:https://github.com/sqlalchemy/sqlalchemy/issues/5645