我在用着latest带DatabaseLibrary的python和机器人框架版本(https://franz-see.github.io/Robotframework-Database-Library/api/1.0.1/DatabaseLibrary.html https://franz-see.github.io/Robotframework-Database-Library/api/1.0.1/DatabaseLibrary.html)
当我尝试使用这样的 Unicode 字符时,我在从数据库中进行 SELECT 时遇到问题: select * from labcamprodfull where PRODUCTNAME like '%ščť%'
然后我执行/运行测试并收到此错误:UnicodeEncodeError:“ascii”编解码器无法对位置 54 中的字符“\xae”进行编码:序号不在范围内(128)
这是我的代码:
*** Settings ***
Resource ../globalVariables.robot
Library DatabaseLibrary
*** Variables ***
${DB_LOAD_CONNECT_STRING} = '${userLoad}/${passwordDb}@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=${hostnameDb})(PORT=${portDb}))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=${sid})))'
${originalSpecialCharacter} ®
*** Test Cases ***
Validate_if_special_character_Original_symbol_is_correctly_saved_in_database
${byte_string}= Encode String To Bytes ${originalSpecialCharacter} UTF-8
log to console bytes is
log to console ${byte_string}
${_string} = Decode Bytes To String ${byte_string} UTF-8
log to console encoded string is
log to console ${_string}
Connect To Database Using Custom Params cx_Oracle ${DB_LOAD_CONNECT_STRING}
${rowCount} Row Count select * from labcamprodfull where PRODUCTNAME like '%${_string}%'
log to console Product count with original symbol in name is
log to console ${rowCount}
Disconnect from database
然后我执行/运行测试并收到此错误:UnicodeEncodeError:“ascii”编解码器无法对位置 54 中的字符“\xae”进行编码:序号不在范围内(128)
cx_Oracle 的默认编码确实是 ASCII。如果您可以在创建时设置连接的编码,那么一切都应该没问题。对于基本的 cx_Oracle,将按如下方式完成:
cx_Oracle.connect(user, password, dsn, encoding="UTF-8", nencoding="UTF-8")
我不确定您正在使用的工具是如何完成的,但希望这足以让您继续前进。
另一个选项是设置环境变量 NLS_LANG,如下所示
export NLS_LANG=.AL32UTF8
然后运行您的应用程序。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)