pdna
pdna

Reputation: 602

Python requests intermittent error `ConnectionError: ('Connection aborted.', BadStatusLine("''",))`

Before: Service-A ===> Service-B (works properly over https)

Now: Service-A ===> Service-B (over http)

I've made sure service A is configured to use http for requests but I get the following error:

[2019-09-02 02:15:11,579] ERROR in app: Exception on /api/users [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "./app/view/__init__.py", line 243, in decorated_function
    return make_request()
  File "./app/view/__init__.py", line 222, in make_request
    response = f(parsed_params)
....
REDACTED
....
  File "./app/user.py", line 620, in create_user
    headers=cls._USER_AGENT_HEADER
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 490, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', BadStatusLine("''",))

If I set the protocol back to https I get Unknown SSLProtocol error, so Service-B is definitely on http.

User-Agent header is set properly. I've tried modifying it to an empty header and a web browser header but it didn't seem to affect anything.

The error seems to occur intermittently and the frequency of the error varies.

Requests version: 2.18.4

Upvotes: 1

Views: 599

Answers (1)

pdna
pdna

Reputation: 602

It was a service discovery issue. Two containers/services were registered with the same name while using registrator. Need to change the docker-compose file

Upvotes: 1

Related Questions