Python HTTP Server/Client: Remote end closed connection without response error

后端 未结 1 1948
-上瘾入骨i
-上瘾入骨i 2020-12-30 23:46

I made simple HTTP Server using BaseHTTPRequestHandler. The problem is, that when I want to post some data using requests from client, I get ConnectionErr

相关标签:
1条回答
  • 2020-12-31 00:24

    It looks like the server is terminating the connection early without sending a full response. I've skimmed the docs and I think this is the problem (emphasis added):

    send_response(code, message=None) 
    

    Adds a response header to the headers buffer and logs the accepted request. The HTTP response line is written to the internal buffer, followed by Server and Date headers. The values for these two headers are picked up from the version_string() and date_time_string() methods, respectively. If the server does not intend to send any other headers using the send_header() method, then send_response() should be followed by an end_headers() call.

    Changed in version 3.3: Headers are stored to an internal buffer and end_headers() needs to be called explicitly.

    So you probably just need to add the call to end_headers. If you were reading an old example (prior to Python 3.3) this wouldn't have been needed.

    0 讨论(0)
提交回复
热议问题