If you find that your requests or urllib.request call in Python 3 cannot save the stream because you get "ICY 200 OK" instead of the "HTTP / 1.0 200 OK" header, you need to tell the main function of ICY 200 OK in order !
What you can do efficiently is to intercept a procedure that processes the reading of the state after opening the stream immediately before processing the headers.
Simply put, as described above, above the stream open code.
def NiceToICY(self): class InterceptedHTTPResponse(): pass import io line = self.fp.readline().replace(b"ICY 200 OK\r\n", b"HTTP/1.0 200 OK\r\n") InterceptedSelf = InterceptedHTTPResponse() InterceptedSelf.fp = io.BufferedReader(io.BytesIO(line)) InterceptedSelf.debuglevel = self.debuglevel InterceptedSelf._close_conn = self._close_conn return ORIGINAL_HTTP_CLIENT_READ_STATUS(InterceptedSelf)
Then place these lines at the beginning of the main procedure before opening the URL.
ORIGINAL_HTTP_CLIENT_READ_STATUS = urllib.request.http.client.HTTPResponse._read_status urllib.request.http.client.HTTPResponse._read_status = NiceToICY
They will redefine the standard procedure (only once) and run the NiceToICY function instead of the usual status check when it opened the stream. NiceToICY replaces the unrecognized response with a state, and then copies the corresponding bits of the original response, which are needed by the "real" function _read_status. Finally, the original is called, and the values ββfrom this are passed back to the caller, and everything else continues as usual.
I found this to be the easiest way to get around the status message issue causing the error. Hope this is useful for you too.
dingles
source share