-
Notifications
You must be signed in to change notification settings - Fork 6k
[QUESTION]httpx.RemoteProtocolError: Server disconnected without sending a response. #3495
Copy link
Copy link
Closed
Closed
Copy link
Description
Issue I am facing
I'm writing a very simple bot app.
The only difference is I'm using HTTP proxy.
Here is my code:
#!/usr/bin/python
#coding: utf-8
TOKEN = "***:***"
PROXY="http://127.0.0.1:3128"
from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler,MessageHandler, filters
from telegram.error import NetworkError
import logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
logger = logging.getLogger(__name__)
async def start(update: Update, context: ContextTypes.context):
logger.info(msg="Start():")
await context.bot.send_message(chat_id=update.effective_chat.id, text="yes!")
async def error_handler(update: Update, context: ContextTypes.context):
logger.error(msg=">>>>>>>>>>>", exc_info=context.error)
if __name__ == '__main__':
#application = ApplicationBuilder().token(TOKEN).build()
application = ApplicationBuilder().token(TOKEN).proxy_url(PROXY).build()
start_handler = CommandHandler('start', start)
application.add_handler(start_handler)
application.add_error_handler(error_handler)
application.run_polling()
This application got network errors every 15 seconds.
The main error message is :telegram.error.NetworkError: httpx HTTPError: Server disconnected without sending a response.
Even though, this app can process the update messages got from user. When user send /start to tgbot, it responses correctly.
Traceback to the issue
2023-01-09 19:16:06,939 - apscheduler.scheduler - INFO - Scheduler started
2023-01-09 19:16:06,939 - telegram.ext._application - INFO - Application started
2023-01-09 19:16:27,739 - telegram.ext._updater - ERROR - Error while getting Updates: httpx HTTPError: Server disconnected without sending a response.
2023-01-09 19:16:27,739 - __main__ - ERROR - >>>>>>>>>>>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
return await self._connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 112, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 91, in handle_async_request
) = await self._receive_response_headers(**kwargs)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 155, in _receive_response_headers
event = await self._receive_event(timeout=timeout)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 205, in _receive_event
raise RemoteProtocolError(msg)
httpcore.RemoteProtocolError: Server disconnected without sending a response.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 183, in do_request
res = await self._client.request(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
response = await self._send_handling_auth(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
response = await self._send_handling_redirects(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
response = await self._send_single_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
response = await transport.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/usr/local/Cellar/python@3.10/3.10.6_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.RemoteProtocolError: Server disconnected without sending a response.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 600, in _network_loop_retry
if not await action_cb():
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 327, in polling_action_cb
raise exc
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 312, in polling_action_cb
updates = await self.bot.get_updates(
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_extbot.py", line 524, in get_updates
updates = await super().get_updates(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 334, in decorator
result = await func(*args, **kwargs) # skipcq: PYL-E1102
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 3584, in get_updates
await self._post(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 422, in _post
return await self._do_post(
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_extbot.py", line 306, in _do_post
return await super()._do_post(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 453, in _do_post
return await request.post(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 165, in post
result = await self._request_wrapper(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 288, in _request_wrapper
raise exc
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 274, in _request_wrapper
code, payload = await self.do_request(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 204, in do_request
raise NetworkError(f"httpx HTTPError: {err}") from err
telegram.error.NetworkError: httpx HTTPError: Server disconnected without sending a response.
2023-01-09 19:16:39,501 - telegram.ext._updater - ERROR - Error while getting Updates: httpx HTTPError: Server disconnected without sending a response.
2023-01-09 19:16:39,501 - __main__ - ERROR - >>>>>>>>>>>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
return await self._connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 112, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 91, in handle_async_request
) = await self._receive_response_headers(**kwargs)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 155, in _receive_response_headers
event = await self._receive_event(timeout=timeout)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 205, in _receive_event
raise RemoteProtocolError(msg)
httpcore.RemoteProtocolError: Server disconnected without sending a response.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 183, in do_request
res = await self._client.request(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
response = await self._send_handling_auth(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
response = await self._send_handling_redirects(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
response = await self._send_single_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
response = await transport.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/usr/local/Cellar/python@3.10/3.10.6_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.RemoteProtocolError: Server disconnected without sending a response.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 600, in _network_loop_retry
if not await action_cb():
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 327, in polling_action_cb
raise exc
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 312, in polling_action_cb
updates = await self.bot.get_updates(
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_extbot.py", line 524, in get_updates
updates = await super().get_updates(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 334, in decorator
result = await func(*args, **kwargs) # skipcq: PYL-E1102
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 3584, in get_updates
await self._post(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 422, in _post
return await self._do_post(
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_extbot.py", line 306, in _do_post
return await super()._do_post(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 453, in _do_post
return await request.post(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 165, in post
result = await self._request_wrapper(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 288, in _request_wrapper
raise exc
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 274, in _request_wrapper
code, payload = await self.do_request(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 204, in do_request
raise NetworkError(f"httpx HTTPError: {err}") from err
telegram.error.NetworkError: httpx HTTPError: Server disconnected without sending a response.
2023-01-09 19:16:51,741 - telegram.ext._updater - ERROR - Error while getting Updates: httpx HTTPError: Server disconnected without sending a response.
2023-01-09 19:16:51,741 - __main__ - ERROR - >>>>>>>>>>>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
return await self._connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 112, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 91, in handle_async_request
) = await self._receive_response_headers(**kwargs)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 155, in _receive_response_headers
event = await self._receive_event(timeout=timeout)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 205, in _receive_event
raise RemoteProtocolError(msg)
httpcore.RemoteProtocolError: Server disconnected without sending a response.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 183, in do_request
res = await self._client.request(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
response = await self._send_handling_auth(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
response = await self._send_handling_redirects(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
response = await self._send_single_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
response = await transport.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/usr/local/Cellar/python@3.10/3.10.6_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.RemoteProtocolError: Server disconnected without sending a response.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 600, in _network_loop_retry
if not await action_cb():
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 327, in polling_action_cb
raise exc
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 312, in polling_action_cb
updates = await self.bot.get_updates(
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_extbot.py", line 524, in get_updates
updates = await super().get_updates(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 334, in decorator
result = await func(*args, **kwargs) # skipcq: PYL-E1102
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 3584, in get_updates
await self._post(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 422, in _post
return await self._do_post(
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_extbot.py", line 306, in _do_post
return await super()._do_post(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 453, in _do_post
return await request.post(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 165, in post
result = await self._request_wrapper(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 288, in _request_wrapper
raise exc
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 274, in _request_wrapper
code, payload = await self.do_request(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 204, in do_request
raise NetworkError(f"httpx HTTPError: {err}") from err
telegram.error.NetworkError: httpx HTTPError: Server disconnected without sending a response.
2023-01-09 19:17:04,708 - telegram.ext._updater - ERROR - Error while getting Updates: httpx HTTPError: Server disconnected without sending a response.
2023-01-09 19:17:04,708 - __main__ - ERROR - >>>>>>>>>>>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
return await self._connection.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 112, in handle_async_request
raise exc
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 91, in handle_async_request
) = await self._receive_response_headers(**kwargs)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 155, in _receive_response_headers
event = await self._receive_event(timeout=timeout)
File "/usr/local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 205, in _receive_event
raise RemoteProtocolError(msg)
httpcore.RemoteProtocolError: Server disconnected without sending a response.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 183, in do_request
res = await self._client.request(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
response = await self._send_handling_auth(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
response = await self._send_handling_redirects(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
response = await self._send_single_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
response = await transport.handle_async_request(request)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/usr/local/Cellar/python@3.10/3.10.6_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.RemoteProtocolError: Server disconnected without sending a response.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 600, in _network_loop_retry
if not await action_cb():
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 327, in polling_action_cb
raise exc
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_updater.py", line 312, in polling_action_cb
updates = await self.bot.get_updates(
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_extbot.py", line 524, in get_updates
updates = await super().get_updates(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 334, in decorator
result = await func(*args, **kwargs) # skipcq: PYL-E1102
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 3584, in get_updates
await self._post(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 422, in _post
return await self._do_post(
File "/usr/local/lib/python3.10/site-packages/telegram/ext/_extbot.py", line 306, in _do_post
return await super()._do_post(
File "/usr/local/lib/python3.10/site-packages/telegram/_bot.py", line 453, in _do_post
return await request.post(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 165, in post
result = await self._request_wrapper(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 288, in _request_wrapper
raise exc
File "/usr/local/lib/python3.10/site-packages/telegram/request/_baserequest.py", line 274, in _request_wrapper
code, payload = await self.do_request(
File "/usr/local/lib/python3.10/site-packages/telegram/request/_httpxrequest.py", line 204, in do_request
raise NetworkError(f"httpx HTTPError: {err}") from err
telegram.error.NetworkError: httpx HTTPError: Server disconnected without sending a response.Related part of your code
No response
Operating System
macOS Monterey 12.6.2
Version of Python, python-telegram-bot & dependencies
python3 -m telegram
python-telegram-bot 20.0
Bot API 6.4
Python 3.10.6 (main, Aug 11 2022, 13:49:25) [Clang 13.1.6 (clang-1316.0.21.2.5)]python3 -V
Python 3.10.6
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels