mpetazzoni / sseclient

Pure-Python Server Side Events (SSE) client
Apache License 2.0
197 stars 33 forks source link

Bug: The url is invalid. No exception is thrown. #31

Closed fgd-haha closed 8 months ago

fgd-haha commented 8 months ago

Bug: The url is invalid. No exception is thrown.

 headers = {
            "X-Request-ID": self.request_id,
        }
        client = sseclient.SSEClient(requests.post(url, json=data, headers=headers, stream=True, timeout=32))
        start = time.time()
        for event in client.events():
            logger.info(f"essay_writer ai_service {self.request.request_id = } {event.data = }")
        # If the url is wrong, instead of throwing an exception, just go to this line
mpetazzoni commented 8 months ago

@fgd-haha You should raise_for_status() if you want to check for this type of condition:

resp = requests.post(url, ...)
resp.raise_for_status()
client = sseclient.SSEClient(resp)
...