How to decompile the blob fields in a SAP ERP using gzip basXml as format with python

107 Views Asked by At

How to decompile blob fields in a SAP ERP using gzip basXml as format with python? In my case I want to read the field "xdata" from the ODQDATA tables.

I tried to unpack the object with gzip and zlib, but that was unsuccessful (BadGzipFile: Not a gzipped file). I have no more ideas myself.

    import zlib
    import gzip
    import base64
    
    jdbcHostname = "xxx"
    jdbcPort = "xx"
    jdbcUrl = f"jdbc:sap://{jdbcHostname}:{jdbcPort}"
    
    jdbcUsername = "xx"
    jdbcPassword = "xx"
    
    query="SELECT * FROM SAPHANADB.ODQDATA LIMIT 1"
    
    df = spark.read \
            .format("jdbc") \
            .option("url", jdbcUrl) \
            .option("query", query) \
            .option("driver", "com.sap.db.jdbc.Driver") \
            .option("user", jdbcUsername) \
            .option("password", jdbcPassword) \
            .load()
    
    #for row in df.collect():
    for row in df.collect():
        blob_data = row["XDATA"]
        data = gzip.decompress blob_data)
0

There are 0 best solutions below