Thanks for the answer.
I found no way to cast in python, but it turned out the the second parameter was not the problem. Or it could not be used the way I tried in the posted code. But just like all the examples online, just use the OrekitEphemerisFile object.
The solution was in the first parameter. Use StringWriter like this:
oem_string = StringWriter()
writer = EphemerisOemWriter(WriterBuilder().buildOemWriter(), oem_header, oem_metadata,
FileFormat.KVN, "dummy", Constants.JULIAN_DAY, 60)
writer.write(oem_string, ep)
fp = open("test_oem.txt", "w")
fp.write(oem_string.toString())
fp.close()
I found this code here https://forum.orekit.org/t/setinterpolationdegree-in-oem-template/1916
-Tommy