我最近開始收到在生產中抓取我的網站的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 機器人)將是從伺服器收到「連線被拒絕」錯誤的機器人 –不是你的網頁應用程式。另外,網頁應用程式甚至不會先處理連線——這是 Heroku 網路伺服器的工作。
仔細看看你的 Python 堆疊追蹤:它從wehealth.utils.get_group()
「celery」非同步任務套件開始,然後到「amqp」訊息傳遞客戶端,最終從 amqp.transport 中報告錯誤。換句話說,您的應用程式無法到達 AMQP 伺服器。