我在我的硬盤驅動器的根目錄中有一個虛擬環境中的Django python服務器。在命令行,當我激活env
並運行python manage.py 192.168.0.47:80
啓動服務器正常(無遷移通知或任何東西),但是當我從瀏覽器加載頁面(使用instancegaming.net
地方,這是我的服務器主機文件,並已工作精細過去本地和遠程)IT負載和負載永遠,當我去Django的服務器窗口,做Ctrl+C
它更新控制檯,給我下面的錯誤。請記住,這env
是全新安裝,比Django的其他沒有其他網站的包。我之前在同一臺服務器上運行過服務器(,Windows 10 64位),並且使用相同的路由器配置。Django Python - 無法建立連接,因爲目標機器主動拒絕它
我看過其他文章這樣(Python Django-Helpdesk Error: No connection could be made because the target machine actively refused it)和其他一些,但這些似乎都沒有解決這個問題。
控制檯窗口:
(env) C:\server\www>python manage.py runserver 192.168.0.47:80
Performing system checks...
System check identified no issues (0 silenced).
December 28, 2016 - 19:07:06
Django version 1.10.4, using settings 'www.settings'
Starting development server at http://192.168.0.47:80/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "C:\server\env\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "C:\server\env\lib\site-packages\django\utils\deprecation.py", line 136, in __call__
response = self.get_response(request)
File "C:\server\env\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
response = response_for_exception(request, exc)
File "C:\server\env\lib\site-packages\django\core\handlers\exception.py", line 86, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\server\env\lib\site-packages\django\core\handlers\exception.py", line 124, in handle_uncaught_exception
extra={'status_code': 500, 'request': request},
File "c:\python\Lib\logging\__init__.py", line 1308, in error
self._log(ERROR, msg, args, **kwargs)
File "c:\python\Lib\logging\__init__.py", line 1415, in _log
self.handle(record)
File "c:\python\Lib\logging\__init__.py", line 1425, in handle
self.callHandlers(record)
File "c:\python\Lib\logging\__init__.py", line 1487, in callHandlers
hdlr.handle(record)
File "c:\python\Lib\logging\__init__.py", line 855, in handle
self.emit(record)
File "C:\server\env\lib\site-packages\django\utils\log.py", line 121, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "C:\server\env\lib\site-packages\django\utils\log.py", line 124, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "C:\server\env\lib\site-packages\django\core\mail\__init__.py", line 103, in mail_admins
mail.send(fail_silently=fail_silently)
File "C:\server\env\lib\site-packages\django\core\mail\message.py", line 342, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\server\env\lib\site-packages\django\core\mail\backends\smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "C:\server\env\lib\site-packages\django\core\mail\backends\smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "c:\python\Lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "c:\python\Lib\smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "c:\python\Lib\smtplib.py", line 306, in _get_socket
self.source_address)
File "c:\python\Lib\socket.py", line 711, in create_connection
raise err
File "c:\python\Lib\socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\python\Lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\server\env\lib\site-packages\django\core\handlers\wsgi.py", line 170, in __call__
response = self.get_response(request)
File "C:\server\env\lib\site-packages\django\core\handlers\base.py", line 124, in get_response
response = self._middleware_chain(request)
File "C:\server\env\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
response = response_for_exception(request, exc)
File "C:\server\env\lib\site-packages\django\core\handlers\exception.py", line 86, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\server\env\lib\site-packages\django\core\handlers\exception.py", line 124, in handle_uncaught_exception
extra={'status_code': 500, 'request': request},
File "c:\python\Lib\logging\__init__.py", line 1308, in error
self._log(ERROR, msg, args, **kwargs)
File "c:\python\Lib\logging\__init__.py", line 1415, in _log
self.handle(record)
File "c:\python\Lib\logging\__init__.py", line 1425, in handle
self.callHandlers(record)
File "c:\python\Lib\logging\__init__.py", line 1487, in callHandlers
hdlr.handle(record)
File "c:\python\Lib\logging\__init__.py", line 855, in handle
self.emit(record)
File "C:\server\env\lib\site-packages\django\utils\log.py", line 121, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "C:\server\env\lib\site-packages\django\utils\log.py", line 124, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "C:\server\env\lib\site-packages\django\core\mail\__init__.py", line 103, in mail_admins
mail.send(fail_silently=fail_silently)
File "C:\server\env\lib\site-packages\django\core\mail\message.py", line 342, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\server\env\lib\site-packages\django\core\mail\backends\smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "C:\server\env\lib\site-packages\django\core\mail\backends\smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "c:\python\Lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "c:\python\Lib\smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "c:\python\Lib\smtplib.py", line 306, in _get_socket
self.source_address)
File "c:\python\Lib\socket.py", line 711, in create_connection
raise err
File "c:\python\Lib\socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
[28/Dec/2016 19:08:15] "GET/HTTP/1.1" 500 59
我settings.py:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = [
'.instancegaming.net',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'www.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'www.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'MST'
USE_I18N = True
USE_L10N = True
USE_TZ = True
ADMINS = (('Jacob J','[email protected]'))
MANAGERS = ADMINS
STATICFILES_DIRS = (
'C:/server/web/static/',
)
STATIC_ROOT = 'C:/server/Apache2/htdocs/cdn/main/'
STATIC_URL = 'http://instancegaming.net:81/cdn/main/'
控制檯錯誤循環永遠上隨時更新我的控制檯日誌(例如,按enter或做Ctrl+C
。 )
當我去canyouseeme.org,在港口8 0當服務器運行時,它說它可以看到服務。另外,我有一個乾淨的Apache 2服務器在端口:81
上運行,在本地和遠程都可以正常工作。另外,當我運行python腳本來簡單地檢查端口80時,它會給出與上面相同的(簡化)錯誤。
端口檢測腳本:
import socket
s = socket.socket()
address = '127.0.0.1' # or 192.168.0.47
port = 80 # port number is a number, not string
try:
s.connect((address, port))
# originally, it was
# except Exception, e:
# but this syntax is not supported anymore.
except Exception as e:
print("something's wrong with %s:%d. Exception is %s" % (address, port, e))
finally:
s.close()
它返回以下
[WinError 10061]無連接可以作出,因爲目標機器積極地拒絕它
最後,我試圖做一個乾淨的env
與Django希望它會改變的東西,但它,一個新的,開箱即可複製完全相同的錯誤。
你運行另一臺機器,或者你是從連接在機器上的服務器? –
你的服務器在'192.168.0.47'上運行,所以你不能在腳本中使用'127.0.0.1'。 – furas
@furas是正確的。嘗試使用'python manage.py runserver 0.0.0.0:80'運行開發服務器。 – Selcuk