Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

decoder setting #47

Open
BG4WCE opened this issue Mar 31, 2020 · 5 comments
Open

decoder setting #47

BG4WCE opened this issue Mar 31, 2020 · 5 comments

Comments

@BG4WCE
Copy link

BG4WCE commented Mar 31, 2020

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.

@btubbs
Copy link
Owner

btubbs commented May 9, 2020

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?

@patrolez
Copy link

patrolez commented May 14, 2020

@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

self.resp.encoding)(errors='replace')

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 2aff290 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.

@andreafresa
Copy link

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

@patrolez
Copy link

@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.

btubbs added a commit that referenced this issue Sep 24, 2020
Fix Issue #47: using Response.apparent_encoding when Response.encoding is None
@cyprienc
Copy link
Contributor

This issue was resolved with PR #51

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants