'NoneType' object has no attribute 'readline'
See original GitHub issueTried a quick check of open issues, but wasn’t sure what to search for on this.
Here’s the code to reproduce:
import shutil
import requests
import os
session = requests.Session()
# it has something to do with content on the 302 from this url
u = 'http://www.amazon.com/gp/redirect.html/ref=gw_m_b_ir?_encoding=UTF8&location=http%3A%2F%2Fphx.corporate-ir.net%2Fphoenix.zhtml%3Fc%3D97664%26p%3Dirol-irhome&source=standards&token=F9CAD8A11D4336B5E0B3C3B089FA066D0A467C1C'
r0 = session.get(u, stream=True, allow_redirects=False)
redirects = session.resolve_redirects(r0, r0.request, stream=True)
for redirect in redirects:
with open(os.devnull, 'wb') as devnull:
shutil.copyfileobj(redirect.raw, devnull)
Gives me the traceback:
(tmp-91018d725433cf2c) gsbrown$ python bug.py
Traceback (most recent call last):
File "bug.py", line 11, in <module>
for redirect in redirects:
File "/Users/gsbrown/.virtualenvs/tmp-91018d725433cf2c/lib/python2.7/site-packages/requests/sessions.py", line 106, in resolve_redirects
resp.content # Consume socket so it can be released
File "/Users/gsbrown/.virtualenvs/tmp-91018d725433cf2c/lib/python2.7/site-packages/requests/models.py", line 781, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "/Users/gsbrown/.virtualenvs/tmp-91018d725433cf2c/lib/python2.7/site-packages/requests/models.py", line 703, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/Users/gsbrown/.virtualenvs/tmp-91018d725433cf2c/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 428, in stream
for line in self.read_chunked(amt, decode_content=decode_content):
File "/Users/gsbrown/.virtualenvs/tmp-91018d725433cf2c/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 590, in read_chunked
self._update_chunk_length()
File "/Users/gsbrown/.virtualenvs/tmp-91018d725433cf2c/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 532, in _update_chunk_length
line = self._fp.fp.readline()
AttributeError: 'NoneType' object has no attribute 'readline'
The redirect url is significant. It doesn’t happen with the httpbin ones.
Issue Analytics
- State:
- Created 7 years ago
- Comments:31 (19 by maintainers)
Top Results From Across the Web
'NoneType' object has no attribute 'readline'" - Stack Overflow
Everything seems to work fine, except when I enter the incorrect file name, loop back, and then enter the correct one. The program...
Read more >'NoneType' object has no attribute 'readline' #3807 - GitHub
I think the simple fix here is to change the check in urllib3 to return getattr(self._fp, 'fp', None) is not None which should...
Read more >731403 - Robocop: ''NoneType' object has no attribute 'readline''
make mochitest-robotium recently started reporting an error: INFO | runtests.py | Received unexpected exception while running application ''NoneType' object ...
Read more >python error AttributeError NoneType object has no attribute ...
I ahve the following python code: import speech_recognition as sr recognizer=sr.Recognizer() mic=sr. ... : 'NoneType' object has no ...
Read more >AttributeError: 'NoneType' object has no attribute 'readlines'
AttributeError : 'NoneType' object has no attribute 'readlines' ... "r") for mot in ofiles.readlines(): mot = mot.strip("\n") hashmd5 ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @mjuarezm, if you can verify that you’re using the dev version of urllib3, both with the warning we emit “RequestsDependencyWarning: urllib3 (dev) or chardet (3.0.4) doesn’t match a supported version!” and with the contents of
requests.packages.urllib3.__version__
being “dev”, you’ll want to open a new ticket since this is 18 months old. I’m unable to reproduce the issue with what you’ve provided with the current master branch of urllib3, so we’ll need more information about your system.@jvanasco Reading the headers should not require
_content_consumed
to beTrue
. If it did, the_content_consumed
flag would be entirely redundant, because we never create aResponse
object without having already read the headers.