Crash "ConnectionError: BadStatusLine"
See original GitHub issueI have a very simple script. It makes an unverified account, sleeps 5 minutes, then does a
get_posts_recent(skip=0, limit=60, after="", mine=False, hashtag="", channel="")
Pretty much taken straight out of the documentation/samples. PS I also tried the version without brackets, get_post_recent() (got the idea from your test file, its in one of the first tests).
However, a random number of cycles (usually 1-5), it will crash, with the error stack:
Traceback (most recent call last):   File "C:\PythonScript\jodler.py", line 31, in <module>     looped_recent = j.get_posts_recent(skip=0, limit=60, after="", mine=False, hashtag="", channel="")   File "C:\Python27\lib\site-packages\jodel_api.py", line 214, in get_posts_recent     return self._get_posts('', skip, limit, after, mine, hashtag, channel, **kwargs)   File "C:\Python27\lib\site-packages\jodel_api.py", line 211, in _get_posts     return self._send_request("GET", url, params=params, **kwargs)   File "C:\Python27\lib\site-packages\jodel_api.py", line 62, in _send_request     resp = s.request(method=method, url=url, params=params, json=payload, headers=headers, **kwargs)   File "C:\Python27\lib\site-packages\requests\sessions.py", line 468, in request     resp = self.send(prep, **send_kwargs)   File "C:\Python27\lib\site-packages\requests\sessions.py", line 576, in send     r = adapter.send(request, **kwargs)   File "C:\Python27\lib\site-packages\requests\adapters.py", line 426, in send     raise ConnectionError(err, request=request) ConnectionError: ('Connection aborted.', BadStatusLine("''",))
Line 31 in my script is as follows:
	looped_recent = j.get_posts_recent(skip=0, limit=60, after="", mine=False, hashtag="", channel="")
Nothing fancy going on, but it dies. Any idea?
Issue Analytics
- State:
 - Created 6 years ago
 - Comments:5 (2 by maintainers)
 

Top Related StackOverflow Question
That error means that you’re receiving a malformed response or the server prematurely terminated the connection (cf [1], [2]).
It’s weird that you are getting the error so often, I can’t remember ever seeing this. It might be due to your specific combination of your OS, python version, ssl lib, even your ISP. Try different machines/connections and see if you’re still getting the error.
If nothing works, I’d recommend generously wrapping this in a
try exceptand retrying upon an error.Anyway, there’s not much
jodel_apican do about that, so I’m closing this issue.[1] https://github.com/kennethreitz/requests/issues/2364
[2] https://bugs.python.org/issue23054
Thanks for getting back to me so quick during a weekend.
I ran into same issues in 2.7 and 3.5. I am not behind a proxy, but i haven’t tested the code on another connection, so it might come down to the connection.
I sat this up as a text-to-speech bot about 4 months ago, and didn’t recall running into any issues back then, so I assumed the API handled these network issues.
Wrapping everything up in try/catch loops works. I also bumped every instance of time.sleep up to double, and have been able to cycle through 72 times now without catching a single exception. Strange.