最近,我开始收到生产中抓取我网站时error: [Errno 111] Connection refused
出现的错误http://yandex.com/bots
。我不介意他们抓取网站,但不想收到这些电子邮件。
我的直觉是,他们被拒绝是因为他们正在使用http
和端口,80
而我的网站需要https
。在这种情况下,他们被拒绝是件好事。但是,我不确定为什么我会收到这些错误(自上周以来每天 4-5 次)。
关于如何阻止这些错误有什么想法吗?我正在使用 Python 2.7、Heroku 和 Cloudflare。
Internal Server Error: /team/46/
Traceback (most recent call last):
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/newrelic/hooks/framework_django.py", line 544, in wrapper
return wrapped(*args, **kwargs)
File "/app/wehealth/wehealth/utils.py", line 121, in __render_with
d = f(request, *args, **kwargs)
File "/app/wehealth/users/views.py", line 737, in team
team = get_group(team, team_id, team_key)
File "/app/wehealth/wehealth/utils.py", line 770, in get_group
group = get_group_goals(group)
File "/app/wehealth/wehealth/utils.py", line 786, in get_group_goals
createGoal2Group.delay(group['info'], g)
File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/task.py", line 453, in delay
return self.apply_async(args, kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/task.py", line 565, in apply_async
**dict(self._get_exec_options(), **options)
File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/base.py", line 354, in send_task
reply_to=reply_to or self.oid, **options
File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/amqp.py", line 305, in publish_task
**kwargs
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/messaging.py", line 172, in publish
routing_key, mandatory, immediate, exchange, declare)
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 470, in _ensured
interval_max)
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 382, in ensure_connection
interval_start, interval_step, interval_max, callback)
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/utils/__init__.py", line 246, in retry_over_time
return fun(*args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 250, in connect
return self.connection
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 756, in connection
self._connection = self._establish_connection()
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 711, in _establish_connection
conn = self.transport.establish_connection()
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 116, in establish_connection
conn = self.Connection(**opts)
File "/app/.heroku/python/lib/python2.7/site-packages/amqp/connection.py", line 165, in __init__
self.transport = self.Transport(host, connect_timeout, ssl)
File "/app/.heroku/python/lib/python2.7/site-packages/amqp/connection.py", line 186, in Transport
return create_transport(host, connect_timeout, ssl)
File "/app/.heroku/python/lib/python2.7/site-packages/amqp/transport.py", line 299, in create_transport
return TCPTransport(host, connect_timeout)
File "/app/.heroku/python/lib/python2.7/site-packages/amqp/transport.py", line 95, in __init__
raise socket.error(last_err)
error: [Errno 111] Connection refused
Request repr():
<WSGIRequest
path:/team/46/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{u'CSRF_COOKIE': u'y8sR9HccmrzW8RaYDQwmalvKiRl2E6DK',
'HTTP_ACCEPT': '*/*',
'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
'HTTP_CONNECTION': 'close',
'HTTP_CONNECT_TIME': '0',
'HTTP_FROM': '[email protected]',
'HTTP_HOST': 'wehealth.herokuapp.com',
'HTTP_TOTAL_ROUTE_TIME': '0',
'HTTP_USER_AGENT': 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
'HTTP_VIA': '1.1 vegur',
'HTTP_X_FORWARDED_FOR': '77.88.47.24, 10.33.252.175',
'HTTP_X_FORWARDED_PORT': '80',
'HTTP_X_FORWARDED_PROTO': 'http',
'HTTP_X_REQUEST_ID': 'a0a5b07f-b6be-40ec-b04a-81690188d0b4',
'HTTP_X_REQUEST_START': '1558372953380',
'PATH_INFO': u'/team/46/',
'QUERY_STRING': '',
'REMOTE_ADDR': 'localhost',
'REQUEST_METHOD': 'GET',
'SCRIPT_NAME': u'',
'SERVER_NAME': 'unix',
'SERVER_PORT': '/tmp/nginx.socket',
'SERVER_PROTOCOL': 'HTTP/1.0',
'SERVER_SOFTWARE': 'waitress',
'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7fc4b5d041e0>,
'wsgi.file_wrapper': <class 'waitress.buffers.ReadOnlyFileBasedBuffer'>,
'wsgi.input': <newrelic.api.wsgi_application._WSGIInputWrapper object at 0x7fc4857e7310>,
'wsgi.multiprocess': False,
'wsgi.multithread': True,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>
更新 因为看起来是我的应用程序导致了错误。以下是与错误相关的异步任务中的代码:
@shared_task
def createGoal2Group(group, goal):
# "Create a Goal2Group link if user completes goal for first time"
goal2group = Goal2Group.objects.get_or_create(group=group, goal=goal)
答案1
不,这些事情的运作方向与你想象的相反。你唯一一次看到“连接被拒绝”的情况是你连接到另一台服务器。
(如果您的服务器不接受 HTTP 连接,那么客户(即 Yandex 机器人)会从服务器收到“连接被拒绝”错误 –不是您的 Web 应用。此外,Web 应用甚至根本不处理连接 - 这是 Heroku Web 服务器的工作。)
仔细查看 Python 堆栈跟踪:它从wehealth.utils.get_group()
“celery”异步任务包开始,然后到“amqp”消息客户端,最终报告 amqp.transport 内部的错误。换句话说,您的应用无法访问 AMQP 服务器。