大家好, 最近用寫左個bot, 宜家有d connection issue 問題想問下高手, 坊間真係搵唔到答案:
以下係我個bot 的code:- def papa_BT_scan(context: telegram.ext.CallbackContext):
- ws_nonFG_bot_web_scraping.papa_bt_scan(context)
- #Server Start
- #===========================================================
- def server_start(update: telegram.Update, context: telegram.ext.CallbackContext):
- print("Telegram_bot_nonFG Started.")
- context.bot.send_message(chat_id=update.message.chat_id,text=':)')
- context.job_queue.run_daily(papa_BT_scan,datetime.time(hour=18, minute=00, tzinfo=pytz.timezone('Asia/Hong_Kong')),context=update.message.chat_id)
-
- if __name__ == "__main__":
- REQUEST_KWARGS = {'proxy_url': 'socks5h://127.0.0.1:9150' }
- u = Updater('<myToken>', use_context=True,request_kwargs=REQUEST_KWARGS)
-
- start_handler = CommandHandler('s', server_start,pass_job_queue=True)
- u.dispatcher.add_handler(start_handler)
-
- u.job_queue.start()
- u.start_polling()
- u.idle()
複製代碼 一開始個陣其實個bot 完全無問題行到, 但過左陣之後(1-2個鐘之後), 就會throw exception:
Error while getting Updates: urllib3 HTTPError SOCKSHTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot1924749319:<mytoken>/getUpdates (Caused by ConnectTimeoutError(<telegram.vendor.ptb_urllib3.urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x116208c90>, 'Connection to api.telegram.org timed out. (connect timeout=5.0)'))
No error handlers are registered, logging exception.
Traceback (most recent call last):
File "/Library/anaconda3/lib/python3.7/site-packages/socks.py", line 809, in connect
negotiate(self, dest_addr, dest_port)
File "/Library/anaconda3/lib/python3.7/site-packages/socks.py", line 444, in _negotiate_SOCKS5
self, CONNECT, dest_addr)
File "/Library/anaconda3/lib/python3.7/site-packages/socks.py", line 524, in _SOCKS5_request
resp = self._readall(reader, 3)
File "/Library/anaconda3/lib/python3.7/site-packages/socks.py", line 276, in _readall
d = file.read(count - len(data))
File "/Library/anaconda3/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
我上網睇過好多同類問題都好似無答案, 暫時試過用Proxy Server / VPN(ExpressVPN) , 但問題依然存在.
好想希望各位高手巴打可以幫幫我  |