@ isquared-KeepitReal Возможно, вы используете более старую версию библиотеки. Я предлагаю опубликовать новый вопрос, если у вас возникли проблемы, чтобы вы могли включить свой код и любые ошибки, которые вы видите

лал простой HTTP-сервер, используяBaseHTTPRequestHandler, Проблема в том, что когда я хочу опубликовать некоторые данные, используя запросы от клиента, я получаюConnectionError, Я сделал простой запрос отrequests документация lib. Также интересно то, что HTTP-сервер будет получать данные от клиента и выводить их на консоль. Я не понимаю, как это возможно.

Клиент:

def post_data():
    """Client method"""
    json_data = {
        'sender': 'User',
        'receiver': 'MY_SERVER',
        'message': 'Hello server! Sending some data.'}
    data_headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
    data_payload = json.dumps(json_data)

    try:
        post = requests.post('http://localhost:8080/post', data=data_payload,
                             headers=data_headers)
        print(post.status_code)
    except ConnectionError as e:
        print("CONNECTION ERROR: ")
        print(e)

HTTP-сервер:

def do_POST(self):
    """Server method"""
    self.send_response(200)
    print("Receiving new data ...")
    content_length = int(self.headers['Content-Length'])
    post_data = self.rfile.read(content_length)
    print(post_data)

Результат сервера:

C:\Users\mypc\Projects\PythonFiles\httpserver>python server.py

Fri Jan  5 01:09:12 2018: HTTP Server started on port 8080.
127.0.0.1 - - [05/Jan/2018 01:09:21] "POST /post HTTP/1.1" 200 -
Receiving new data ...
b'{"sender": "User", "receiver": "MY_SERVER", "message": "Hello server! Sending some data."}'

Результат клиента:

C:\Users\mypc\Projects\PythonFiles\httpserver>python client.py
CONNECTION ERROR:
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

C:\Users\mypc\Projects\PythonFiles\httpserver>

Ошибка без исключения блока:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:\Python36\lib\site-packages\urllib3\connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "C:\Python36\lib\site-packages\urllib3\connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Python36\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Python36\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Python36\lib\http\client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\requests\adapters.py", line 440, in send
    timeout=timeout
  File "C:\Python36\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Python36\lib\site-packages\urllib3\util\retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Python36\lib\site-packages\urllib3\packages\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Python36\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:\Python36\lib\site-packages\urllib3\connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "C:\Python36\lib\site-packages\urllib3\connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Python36\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Python36\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Python36\lib\http\client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "client.py", line 137, in <module>
    start_parser()
  File "client.py", line 101, in start_parser
    send_requests(args.get, args.post)
  File "client.py", line 51, in send_requests
    post_data()
  File "client.py", line 129, in post_data
    headers=data_headers)
  File "C:\Python36\lib\site-packages\requests\api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "C:\Python36\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python36\lib\site-packages\requests\sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python36\lib\site-packages\requests\sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python36\lib\site-packages\requests\adapters.py", line 490, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

Ответы на вопрос(1)

Ваш ответ на вопрос