I am getting:
Traceback (most recent call last):
File "/var/www/virtualenvs/myProj/local/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/var/www/virtualenvs/myProj/local/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/var/www/myProj/myProj/apps/myProj/tasks.py", line 43, in get_somestuff
str_response = urllib2.urlopen(req)
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 407, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 520, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 445, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 500: Internal Server Error
when I run task in prod server, locally it is working perfectly.
the bit is
urllib2.urlopen(req)
what may I be missing? the url I am reading is available thru browser
Related
I'm trying to deploy my telegram-bot on PythonAnywhere. It has worked fine with the free account but there are some troubles with the paid one. I'm getting "OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')]" messages in Error logs (accordingly bot works wrong). How can I solve it?
I'm using python3.7 + pyTelegramBotAPI + flask
Code example for error reproducing:
# coding=utf-8
import telebot
import flask
import time
token = 'bot_token'
bot = telebot.TeleBot(token, threaded=False)
WEBHOOK_HOST = '*userName*.pythonanywhere.com'
WEBHOOK_URL_BASE = "https://%s" % (WEBHOOK_HOST)
WEBHOOK_URL_PATH = "/%s/" % (token)
app = flask.Flask(__name__)
# Process webhook calls
#app.route(WEBHOOK_URL_PATH, methods=['POST'])
def webhook():
if flask.request.headers.get('content-type') == 'application/json':
json_string = flask.request.get_data().decode('utf-8')
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return ''
else:
flask.abort(403)
#bot.message_handler(commands=['start', 'help'])
def handle_start_help(message):
bot.send_message(message.chat.id, text="Hello, my friend")
bot.remove_webhook()
time.sleep(0.1)
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH)
Full error trace:
2018-10-30 12:40:33,351: Exception on /*token*/ [POST]
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/kleratoni/bot/bot/Main.py", line 90, in webhook
bot.process_new_updates([update])
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 326, in process_new_updates
self.process_new_callback_query(new_callback_querys)
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 354, in process_new_callback_query
self._notify_command_handlers(self.callback_query_handlers, new_callback_querys)
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 1490, in _notify_command_handlers
self._exec_task(message_handler['function'], message)
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 464, in _exec_task
task(*args, **kwargs)
File "/home/*accountName*/bot/bot/Main.py", line 535, in callback_inline
MainMenuActions.BetMenu_BackButton(call.message, bot, db)
File "/home/*accountName*/bot/bot/MainMenuActions.py", line 130, in BetMenu_BackButton
bot.send_message(message.chat.id, text=config.StringContent["StartPlayWords"], reply_markup=keyborads.keyboardMainmenu)
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 598, in send_message
reply_markup, parse_mode, disable_notification))
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/apihelper.py", line 140, in send_message
return _make_request(token, method_url, params=payload, method='post')
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/apihelper.py", line 54, in _make_request
timeout=(connect_timeout, read_timeout), proxies=proxy)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.7/http/client.py", line 1321, in getresponse
response.begin()
File "/usr/lib/python3.7/http/client.py", line 296, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.7/http/client.py", line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 300, in recv_into
return self.recv_into(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 285, in recv_into
return self.connection.recv_into(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/OpenSSL/SSL.py", line 1814, in recv_into
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3.7/site-packages/OpenSSL/SSL.py", line 1639, in _raise_ssl_error
_raise_current_error()
File "/usr/lib/python3.7/site-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')]
From an issue on the pyTelegramBotAPI github repo, it looks like it's an incompatibility between the version of requests you're using and the version of OpenSSL you're using. Try using requests 2.10.0 instead.
I had a same error and I fixed like this
token = 'bot_token'
bot = telebot.TeleBot(token, threaded=False)
I could use some help deciphering the following traceback and resolving specifically on a linux machine running apache and django with DEBUG = False
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 218, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 256, in handle_uncaught_exception
'request': request
File "/usr/lib/python2.7/logging/__init__.py", line 1200, in error
self._log(ERROR, msg, args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1293, in _log
self.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1303, in handle
self.callHandlers(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1343, in callHandlers
hdlr.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 766, in handle
self.emit(record)
File "/usr/local/lib/python2.7/dist-packages/django/utils/log.py", line 129, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "/usr/local/lib/python2.7/dist-packages/django/utils/log.py", line 132, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/__init__.py", line 98, in mail_admins
mail.send(fail_silently=fail_silently)
...
error: [Errno 111] Connection refused
It is unclear to me why send_mail(..., fail_silently=True, ...) should fail if fail_silently=True
How do I debug this error if it only manifests when DEBUG = False?
If the website I'm trying to connect to via a proxy is unsecured (HTTP), then I'm able to connect, however if it's secured (HTTPS), then I can't.
The following code works:
import urllib2
proxy_support = urllib2.ProxyHandler({'http':'xxx.xxx.xxx.xx'})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
html = urllib2.urlopen('http://www.example.com').read()
However the code below does not work,
proxy_support = urllib2.ProxyHandler({'https':'xxx.xxx.xxx.xx'})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
html = urllib2.urlopen('https://www.example.com').read()
Instead I get the following traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 61] Connection refused>
According to https://docs.python.org/2/library/urllib2.html:
Changed in version 2.7.9: cafile, capath, cadefault, and context were added.
This one allowed me to connect to my local HTTPS site that is using a self-signed SSL certificate:
html = urllib2.urlopen('http://www.example.com'),\
context=ssl._https_verify_certificates(False)
I noticed in your traceback the similarities with mine. The code, just like you posted, works on Ubuntu 14.04 (Python 2.7.6) but not in 16.04 (Python 2.7.13) with exception to the last one:
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 429, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 447, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1241, in https_open
context=self._context)
File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>
I'm not sure if this work on your end.
I'm trying to pull the source from a url in terminal and I'm getting this: As far I can tell everything is in the right place.
response = urllib2.urlopen(url)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden
I'm trying to export Django comments to the django-disqus app. When I run python manage.py disqus_export --verbosity=0, I get the following error lines:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/home/xx/webapps/xx/lib/python2.5/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/xx/webapps/xx/lib/python2.5/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/xx/webapps/xx/lib/python2.5/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/xx/webapps/xx/lib/python2.5/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/xx/lib/python2.5/django_disqus-0.4.1-py2.5.egg/disqus/management/commands/disqus_export.py", line 80, in handle
forum_list = client.get_forum_list(user_api_key=settings.DISQUS_API_KEY)
File "/home/xx/lib/python2.5/django_disqus-0.4.1-py2.5.egg/disqus/api.py", line 53, in call_method
return self.call(attr, **kwargs)
File "/home/xx/lib/python2.5/django_disqus-0.4.1-py2.5.egg/disqus/api.py", line 79, in call
response = urllib2.urlopen(request)
File "/usr/local/lib/python2.5/urllib2.py", line 124, in urlopen
return _opener.open(url, data)
File "/usr/local/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
File "/usr/local/lib/python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/local/lib/python2.5/urllib2.py", line 425, in error
return self._call_chain(*args)
File "/usr/local/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/usr/local/lib/python2.5/urllib2.py", line 506, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: BAD REQUEST
See here: http://readthedocs.org/docs/django-disqus/en/latest/commands.html#disqus-export
The --dry-run command works, however, so I'm not sure what's going on.
Disqus may return a 400 if invalid credentials are provided. It's been a while since I've looked at django-disqus, but can you confirm that whatever credentials you've supplied are valid?