icatproject / icat.server

The ICAT server offering both SOAP and "RESTlike" interfaces to a metadata catalog.
Other
1 stars 5 forks source link

Fix icatadmin to run with Python 3 #306

Closed RKrahl closed 1 year ago

RKrahl commented 1 year ago

Debugging icatadmin for #305 reveals, the issue occurs in line 117:

    if parameters and method == "POST":
        conn.send(parameters)

parameters is the result of a urllib.parse.urlencode() call, which returns a string. conn is either a http.client.HTTPConnection or a http.client.HTTPSConnection, conn.send() seem to require a bytes-like object rather than a string (the official Python docu is not very clear in that point, but experiemts confirm this). So the obvious fix is to convert the string to bytes.

Fix #305.

Note that I only implemented a minimal fix. There are other lines of code that feed strings into conn.send(), as in:

    elif body:
        blocksize = 8192
        datablock = body.read(blocksize)
        crc32 = 0
        while datablock:
            conn.send(hex(len(datablock))[2:] + "\r\n")
            conn.send(datablock + "\r\n")
            crc32 = zlib.crc32(datablock, crc32)
            datablock = body.read(blocksize)
        conn.send("0\r\n\r\n")

I didn't bother to fix those, because:

  1. icatadmin is awkward and should probably rather be rewritten from scratch.
  2. those lines cited above are actually never executed, because the keyword arguments headers and body to _process() are never used and thus body will always be None.
RKrahl commented 1 year ago

Dear @patrick-austin, you are completely right, many thanks for your fixes! I'm happy with your changes.