PosixPath error when loading schema

9 views
Skip to first unread message

Kyle Downey

unread,
Jun 1, 2021, 10:35:19 AMJun 1
to Cap'n Proto
I have the following simple schema:

@0x8fe87a03768154e9;

enum Side {
buy @0;
sell @1;
}

struct TradeMessage {
time @0 : Float64;
tradeId @1 : Int64;
side @2 : Side;
size @3 : Float64;
price @4 : Float64;
}

struct Level1BookUpdateMessage {
time @0 : Float64;
best_bid_qty @1 : Float64;
best_bid_px @2 : Float64;
best_ask_qty @3 : Float64;
best_ask_px @4 : Float64;
}

which I am loading as follows using pycapnp 1.0.0 on MacOS 11.4 running Python 3.8:

import capnp

from pathlib import Path

capnp_path = Path(__file__).parent / '../../../../capnp/serenity-fh.capnp'
capnp_def = capnp.load(capnp_path)

It fails on load with the following error. Any ideas on what I might be doing wrong?

Connected to pydev debugger (build 202.6397.98)
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/kdowney/dev/shadows/serenity/src/serenity/marketdata/fh/txlog.py", line 6, in <module>
    capnp_def = capnp.load(capnp_path)
  File "capnp/lib/capnp.pyx", line 4030, in capnp.lib.capnp.load
  File "capnp/lib/capnp.pyx", line 3276, in capnp.lib.capnp.SchemaParser.load
AttributeError: 'PosixPath' object has no attribute 'endswith'

Kenton Varda

unread,
Jun 1, 2021, 10:41:08 AMJun 1
to Kyle Downey, Cap'n Proto
Hi Kyle,

I think you need to convert `capnp_path` back into a string before passing it to `capnp.load()`. Currently it appears you are passing a `Path` object that you constructed using pathlib, but `capnp.load` doesn't know how to deal with those, it wants a plain string.

-Kenton



--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/26dda48a-5ca0-4b0c-a42f-930d96b388a4n%40googlegroups.com.

Kyle Downey

unread,
Jun 1, 2021, 3:57:33 PMJun 1
to Kenton Varda, Cap'n Proto
Yep that was it. Casting via str() did the trick.
Reply all
Reply to author
Forward
0 new messages