So, i use PyTelegramBotAPI to send messages to my channel with help of bot. Today i need to setup Proxy for my bot, i read docs https://github.com/eternnoir/pyTelegramBotAPI#proxy
Do like that:
import telebot
from telebot import apihelper
bot = telebot.TeleBot(config.telebot_token)
apihelper.proxy = {'https', 'socks5://login:pass@12.11.22.33:8000'}
And got exception:
Connected to pydev debugger (build 172.3757.67)
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1023, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/Stas/PycharmProjects/newsbot/parser.py", line 658, in <module>
RssProcess('rsslinks.txt')
File "/Users/Stas/PycharmProjects/newsbot/parser.py", line 511, in __init__
telegrambot.bot.send_message(config.telebot_id, 'RssProcess Started...')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telebot/__init__.py", line 439, in send_message
reply_markup, parse_mode, disable_notification))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telebot/apihelper.py", line 135, in send_message
return _make_request(token, method_url, params=payload, method='post')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telebot/apihelper.py", line 54, in _make_request
timeout=(connect_timeout, read_timeout), proxies=proxy)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/sessions.py", line 499, in request
prep.url, proxies, stream, verify, cert
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/sessions.py", line 671, in merge_environment_settings
no_proxy = proxies.get('no_proxy') if proxies is not None else None
AttributeError: 'set' object has no attribute 'get'
I try to read what is wrong and found such code:
if self.trust_env:
# Set environment's proxies.
no_proxy = proxies.get('no_proxy') if proxies is not None else None
env_proxies = get_environ_proxies(url, no_proxy=no_proxy)
for (k, v) in env_proxies.items():
proxies.setdefault(k, v)
# Look for requests environment configuration and be compatible
# with cURL.
if verify is True or verify is None:
verify = (os.environ.get('REQUESTS_CA_BUNDLE') or
os.environ.get('CURL_CA_BUNDLE'))
Main problem in line
no_proxy = proxies.get('no_proxy')
I use PyCharm, with installed
PySocks 1.6.8 and Requests 2.18.4
How to connect through Proxy to telegram with my proxy? Also that proxy good work on my phone and PC.