Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ChunkedEncodingError when streaming quotes outside market hours #65

Open
zenahirsch opened this issue Apr 5, 2021 · 1 comment
Open

Comments

@zenahirsch
Copy link

zenahirsch commented Apr 5, 2021

I'm not sure if this is just an issue on Ally's end, BUT I've found that outside market hours, I get the following error when streaming quotes:

Traceback (most recent call last):
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/urllib3/response.py", line 697, in _update_chunk_length
    self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/urllib3/response.py", line 438, in _error_catcher
    yield
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/urllib3/response.py", line 764, in read_chunked
    self._update_chunk_length()
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/urllib3/response.py", line 701, in _update_chunk_length
    raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'', 0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/requests/models.py", line 753, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/urllib3/response.py", line 572, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/urllib3/response.py", line 793, in read_chunked
    self._original_response.close()
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/urllib3/response.py", line 455, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/zena.hirsch/Code/laboratory/stock-watcher.py", line 82, in <module>
    main()
  File "/Users/zena.hirsch/Code/laboratory/stock-watcher.py", line 72, in main
    for quote in a.stream(SYMBOL):
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/ally/Api.py", line 242, in request
    for chunk in x.iter_content( chunk_size=1 ):
  File "/Users/zena.hirsch/Code/.virtualenvs/laboratory/lib/python3.9/site-packages/requests/models.py", line 756, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

I am streaming quotes like so:

for quote in a.stream(SYMBOL):
    print(quote)
    bid_price = float(quote['bid'])

Is this a known issue? Something I should report to Ally? Thank you!

@LaikaN57
Copy link
Collaborator

LaikaN57 commented Apr 9, 2021

hmm.... interesting. The requests library is expecting something like:

HTTP/1.1 200 OK 
Content-Type: text/plain 
Transfer-Encoding: chunked

9\r\n
Some data\r\n 
6\r\n
Python\r\n

but instead of the chunk lengths we are just getting an empty line? We should inspect a packet capture first and then report to Ally. We can also just code around this.

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

No branches or pull requests

2 participants