【问题标题】:Python Quickfix GetString() has Coredump OR Unicode Encode Error for strings >= 16 CharactersPython Quickfix GetString() 对 >= 16 个字符的字符串有 Coredump 或 Unicode 编码错误
【发布时间】:2019-01-23 20:51:14
【问题描述】:

以下 sn-p 代码(在从 quickfix.Application 派生的类中)以字符串形式检索 QuoteReqID 时 coredumps/SIGSEGV。我玩过 QuoteReqID 的大小,并注意到值

import quickfix as fix

...

def fromApp(self, message, session_id):
    msg_type = fix.MsgType()
    message.getHeader().getField(msg_type)
    if msg_type.getString() is fix.MsgType_QuoteRequest:
        quote_req_id_field = message.getField(fix.QuoteReqID())
        quote_req_id = quote_req_id_field.getString()
        print(quote_req_id)

我似乎无法复制 coredump 与 UnicodeEncodeError 所需的条件。当 UnicodeEncodeError 确实发生时,它在 FIX 日志中是这样的:

15 Characters
Original String=samplequotereqs
131=samplequotereqs

16 Characters
Original String=samplequotereqs
131=        otereqs1

在第二个例子中,'otereqs1' 前面不是空格,而是一个白色清晰的垂直 unicode 块字符,我认为它是 U+25AF。

【问题讨论】:

    标签: python python-3.6 swig python-unicode quickfix


    【解决方案1】:

    我访问字段的方式不正确。这是正确的方法:

    def fromApp(self, message, session_id):
        msg_type = fix.MsgType()
        message.getHeader().getField(msg_type)
        if msg_type.getString() is fix.MsgType_QuoteRequest:
            quote_req_id = fix.QuoteReqID()
            message.getField(quote_req_id)
            print(quote_req_id.getValue())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-11
      • 2013-10-29
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 2018-09-30
      • 1970-01-01
      • 2014-04-16
      相关资源
      最近更新 更多