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

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

Closed
Lukasa opened this issue Sep 22, 2014 · 2 comments

Comments

@Lukasa
Copy link
Member

commented Sep 22, 2014

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.

@tijko

This comment has been minimized.

Copy link
Contributor

commented Sep 22, 2014

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

@Lukasa

This comment has been minimized.

Copy link
Member Author

commented Sep 22, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.