Python3 bottle requests proxy altering host hanging and raises BrokenPipeError under wsgiref module
I'm using Bottle in python to make a simple app proxy.
And I just want to change the host, the code is like below:
def get_proxy_response():
print('>>>> START')
resp = requests.request('get', 'http://127.0.0.1:18080/', headers=dict(Host='www.mysite.com'))
print('<<<< FINISH')
return resp
The code works in my development laptop, but when I put the code in production(CentOS6 with Python3.4.8), it was hanging in the request line, and kept for a long time, finally raises the below error, and then causes a 504 response:
>>>> START
127.0.0.1 - - [12/Nov/2018 20:59:57] "GET /index.html HTTP/1.0" 504 1229
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1')
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib64/python3.4/socket.py", line 398, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
127.0.0.1 - - [12/Nov/2018 20:59:57] "GET /index.html HTTP/1.0" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 43046)
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1')
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib64/python3.4/socket.py", line 398, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 141, in run
self.handle_error()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 368, in handle_error
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/socketserver.py", line 305, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib64/python3.4/socketserver.py", line 331, in process_request
self.finish_request(request, client_address)
File "/usr/lib64/python3.4/socketserver.py", line 344, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib64/python3.4/socketserver.py", line 673, in __init__
self.handle()
File "/usr/lib64/python3.4/wsgiref/simple_server.py", line 133, in handle
handler.run(self.server.get_app())
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 144, in run
self.close()
File "/usr/lib64/python3.4/wsgiref/simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
The more confusing thing is that the situation depends on the host name what i set, my backend application will return the right content when I get with Host: www.mysite.com, while other will returns a simple Site not found content.
So if I set the request header to headers=dict(Host='www.yoursite.com'), it finished as expect which telling the right Site not found content.
python http python-requests bottle
add a comment |
I'm using Bottle in python to make a simple app proxy.
And I just want to change the host, the code is like below:
def get_proxy_response():
print('>>>> START')
resp = requests.request('get', 'http://127.0.0.1:18080/', headers=dict(Host='www.mysite.com'))
print('<<<< FINISH')
return resp
The code works in my development laptop, but when I put the code in production(CentOS6 with Python3.4.8), it was hanging in the request line, and kept for a long time, finally raises the below error, and then causes a 504 response:
>>>> START
127.0.0.1 - - [12/Nov/2018 20:59:57] "GET /index.html HTTP/1.0" 504 1229
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1')
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib64/python3.4/socket.py", line 398, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
127.0.0.1 - - [12/Nov/2018 20:59:57] "GET /index.html HTTP/1.0" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 43046)
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1')
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib64/python3.4/socket.py", line 398, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 141, in run
self.handle_error()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 368, in handle_error
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/socketserver.py", line 305, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib64/python3.4/socketserver.py", line 331, in process_request
self.finish_request(request, client_address)
File "/usr/lib64/python3.4/socketserver.py", line 344, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib64/python3.4/socketserver.py", line 673, in __init__
self.handle()
File "/usr/lib64/python3.4/wsgiref/simple_server.py", line 133, in handle
handler.run(self.server.get_app())
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 144, in run
self.close()
File "/usr/lib64/python3.4/wsgiref/simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
The more confusing thing is that the situation depends on the host name what i set, my backend application will return the right content when I get with Host: www.mysite.com, while other will returns a simple Site not found content.
So if I set the request header to headers=dict(Host='www.yoursite.com'), it finished as expect which telling the right Site not found content.
python http python-requests bottle
add a comment |
I'm using Bottle in python to make a simple app proxy.
And I just want to change the host, the code is like below:
def get_proxy_response():
print('>>>> START')
resp = requests.request('get', 'http://127.0.0.1:18080/', headers=dict(Host='www.mysite.com'))
print('<<<< FINISH')
return resp
The code works in my development laptop, but when I put the code in production(CentOS6 with Python3.4.8), it was hanging in the request line, and kept for a long time, finally raises the below error, and then causes a 504 response:
>>>> START
127.0.0.1 - - [12/Nov/2018 20:59:57] "GET /index.html HTTP/1.0" 504 1229
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1')
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib64/python3.4/socket.py", line 398, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
127.0.0.1 - - [12/Nov/2018 20:59:57] "GET /index.html HTTP/1.0" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 43046)
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1')
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib64/python3.4/socket.py", line 398, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 141, in run
self.handle_error()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 368, in handle_error
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/socketserver.py", line 305, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib64/python3.4/socketserver.py", line 331, in process_request
self.finish_request(request, client_address)
File "/usr/lib64/python3.4/socketserver.py", line 344, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib64/python3.4/socketserver.py", line 673, in __init__
self.handle()
File "/usr/lib64/python3.4/wsgiref/simple_server.py", line 133, in handle
handler.run(self.server.get_app())
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 144, in run
self.close()
File "/usr/lib64/python3.4/wsgiref/simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
The more confusing thing is that the situation depends on the host name what i set, my backend application will return the right content when I get with Host: www.mysite.com, while other will returns a simple Site not found content.
So if I set the request header to headers=dict(Host='www.yoursite.com'), it finished as expect which telling the right Site not found content.
python http python-requests bottle
I'm using Bottle in python to make a simple app proxy.
And I just want to change the host, the code is like below:
def get_proxy_response():
print('>>>> START')
resp = requests.request('get', 'http://127.0.0.1:18080/', headers=dict(Host='www.mysite.com'))
print('<<<< FINISH')
return resp
The code works in my development laptop, but when I put the code in production(CentOS6 with Python3.4.8), it was hanging in the request line, and kept for a long time, finally raises the below error, and then causes a 504 response:
>>>> START
127.0.0.1 - - [12/Nov/2018 20:59:57] "GET /index.html HTTP/1.0" 504 1229
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1')
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib64/python3.4/socket.py", line 398, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
127.0.0.1 - - [12/Nov/2018 20:59:57] "GET /index.html HTTP/1.0" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 43046)
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 332, in send_headers
self.send_preamble()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1')
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 453, in _write
self.stdout.write(data)
File "/usr/lib64/python3.4/socket.py", line 398, in write
return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 141, in run
self.handle_error()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 368, in handle_error
self.finish_response()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/socketserver.py", line 305, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib64/python3.4/socketserver.py", line 331, in process_request
self.finish_request(request, client_address)
File "/usr/lib64/python3.4/socketserver.py", line 344, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib64/python3.4/socketserver.py", line 673, in __init__
self.handle()
File "/usr/lib64/python3.4/wsgiref/simple_server.py", line 133, in handle
handler.run(self.server.get_app())
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 144, in run
self.close()
File "/usr/lib64/python3.4/wsgiref/simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
The more confusing thing is that the situation depends on the host name what i set, my backend application will return the right content when I get with Host: www.mysite.com, while other will returns a simple Site not found content.
So if I set the request header to headers=dict(Host='www.yoursite.com'), it finished as expect which telling the right Site not found content.
python http python-requests bottle
python http python-requests bottle
asked Nov 12 at 13:06
Alfred Huang
8,9191877131
8,9191877131
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262833%2fpython3-bottle-requests-proxy-altering-host-hanging-and-raises-brokenpipeerror-u%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262833%2fpython3-bottle-requests-proxy-altering-host-hanging-and-raises-brokenpipeerror-u%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown