sseclient
sseclient copied to clipboard
decoder setting
Hi, I use sseclient to send a request to https://api.trafikinfo.trafikverket.se/v2/data.json, and the got the following error
decoder = lookup(encoding).incrementaldecoder
TypeError: lookup() argument must be str, not None
But when I am looking into the test scripts or examples from programcreek.com, I don't see any example were setting encoder or decoder in the request.
Can someone help? Thanks a lot.
Hi, sorry to hear you're having a problem. I'm not following your description of it though. Can you provide a code snippet of what you're trying to do? Are you sure that endpoint you linked provides an SSE stream?
@btubbs Hello. I can confirm that it happens also for me.
Error
File "/builds/Sse.py", line XYZ, in ASDASDASDASD
for event in self._client:
File "/usr/lib/python3.8/site-packages/sseclient.py", line 100, in __next__
self._connect()
File "/usr/lib/python3.8/site-packages/sseclient.py", line 58, in _connect
self.decoder = codecs.getincrementaldecoder(
File "/usr/lib/python3.8/codecs.py", line 995, in getincrementaldecoder
decoder = lookup(encoding).incrementaldecoder
TypeError: lookup() argument must be str, not None
Where:
self._client = SSEClient(url, retry=0, verify=False)
self._client.resp.raise_for_status()
Seems like it is problem with https://github.com/btubbs/sseclient/blob/bb36b9e273e51fbbf15212cf3d17e464cc6e04c9/sseclient.py#L59
Where:
self.resp.encoding
seems to be None
https://2.python-requests.org/en/master/api/#requests.Response.encoding
The server's endpoint
Java Spring SseEmiter is being used as a server. In this case it works via Nginx:
HTTP/1.1 200
Server: nginx/1.18.0
Date: Thu, 14 May 2020 01:05:36 GMT
Content-Type: text/event-stream;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
That is a Header response for the SSE end-point.
What I have noticed
There is a lot of dependencies, but regarding changes where SSEClient was working I can conclude that:
- sseclient-0.0.24 was passing the tests
- sseclient-0.0.26 fails while showing the error above
Exploring the repo
Commit https://github.com/btubbs/sseclient/commit/2aff29003e6372b6ec19d1aac75e59d396d67d74 has added this line without ensuring that passed parameter is not None
Guesses
Most likely requests
library is not preparing its Response object properly despite charset
present in HTTP server Response, so it is being left with None
value in its .encoding
property.
Hey did you solve it? I am having the same issue here using an http client thatr needs to comunicate with a Leshan LWM2M Server
@andreafresa in my case sseclient-0.0.24
was enough to make everything work properly, so I have pinned this specific version to my project.
This issue was resolved with PR #51