2016-12-29 64 views
1

我在我的硬盘驱动器的根目录中有一个虚拟环境中的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希望它会改变的东西,但它,一个新的,开箱即可复制完全相同的错误。

+0

你运行另一台机器,或者你是从连接在机器上的服务器? –

+2

你的服务器在'192.168.0.47'上运行,所以你不能在脚本中使用'127.0.0.1'。 – furas

+0

@furas是正确的。尝试使用'python manage.py runserver 0.0.0.0:80'运行开发服务器。 – Selcuk

回答

1

最后我很容易地解决这个问题。我最初虽然有一些东西需要与插座80,但做了一些深层次的思考后,我转身DEBUG = True并且发现了我的家目录丢失的模板,并链接到未知网页。对于有此错误的人,请尝试打开DEBUG,如果可以的话。

相关问题