Python请求间歇性错误`ConnectionError:('Connection aborted。',BadStatusLine(“''”,))

时间:2019-09-02 02:32:26

标签: python-2.7 python-requests

之前Service-A ===> Service-B在{em> https上正常工作)

现在Service-A ===> Service-B http上)

我确保将service A配置为使用 http 进行请求,但是出现以下错误:

[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("''",))

如果我将协议重新设置为 https ,则会收到Unknown SSLProtocol错误,因此Service-B肯定位于 http 上。

User-Agent标头设置正确。我尝试将其修改为一个空的标头和一个web browser标头,但似乎没有任何影响。

错误似乎是间歇性发生的,并且错误的频率有所不同。

请求版本: 2.18.4

1 个答案:

答案 0 :(得分:1)

这是一个服务发现问题。使用registrator时以相同的名称注册了两个容器/服务。需要更改docker-compose文件