Skip to content

Multiple calls to iter* fail with unhelpful error. #2240

Closed
@Lukasa

Description

@Lukasa

If you call the iter* methods more than once for a single streamed request, it fails with an extremely unhelpful error:

>>> r = requests.get('http://www.google.com/', stream=True)
>>> [x for x in r.iter_content(1024)]
>>> [x for x in r.iter_content(1024)]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/requests/utils.py", line 341, in iter_slices
    while pos < len(string):
TypeError: object of type 'bool' has no len()

I think it's fine that you can't call the iter* methods twice on a streamed response, but we can easily catch this situation so we should.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions