Skip to content

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

Closed

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

  1. tijko commented on Sep 22, 2014

    @tijko
    Contributor

    I'm making a pull request with a RuntimeError being raised. What kind of exception would you ideally like to throw here?

  2. Lukasa commented on Sep 22, 2014

    @Lukasa
    MemberAuthor

    I'm going to close this to centralise on #2241.

  3. locked as resolved and limited conversation to collaborators on Sep 8, 2021
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

      Sponsor
      SponsoredKunjungi sekarang
      Promo