关于python:从Django admin发布时的Django ConnectionError(urllib3.connection.HTTPConnection)

Django ConnectionError (urllib3.connection.HTTPConnection) while posting from Django admin

错误信息:

1
2
3
4
5
6
7
Exception Type: ConnectionError at /admin/items/country/add/
Exception Value: ConnectionError (<urllib3.connection.HTTPConnection
object at 0x111377110>: Failed to establish a new connection: [Errno
61] Connection refused) caused by:
NewConnectionError(<urllib3.connection.HTTPConnection object at
0x111377110>: Failed to establish a new connection: [Errno 61]
Connection refused)

我从Django管理员保存帖子时收到此连接错误。 我有一个带设置的MYSQL数据库

1
2
3
4
5
6
7
8
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mystic_db',
        'USER': 'root',
        'PASSWORD': '*****',
        'HOST': '',
        'PORT': '',

我是Django Python的新手。 请求解决这个问题?

追溯:

File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
616. return self.admin_site.admin_view(view)(*args, **kwargs)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
110. response = view_func(request, *args, **kwargs)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
233. return view(request, *args, **kwargs)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
1516. return self.changeform_view(request, None, form_url, extra_context)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
34. return bound_func(*args, **kwargs)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
110. response = view_func(request, *args, **kwargs)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
30. return func.get(self, type(self))(*args2, **kwargs2)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/utils/decorators.py" in inner
145. return func(*args, **kwargs)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view
1467. self.save_model(request, new_object, form, not add)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/contrib/admin/options.py" in save_model
1078. obj.save()
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/db/models/base.py" in save
710. force_update=force_update, update_fields=update_fields)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/db/models/base.py" in save_base
747. update_fields=update_fields, raw=raw, using=using)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
201. response = receiver(signal=self, sender=sender, **named)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/haystack/signals.py" in handle_save
52. index.update_object(instance, using=using)
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/haystack/indexes.py" in update_object
284. backend.update(self, [instance])
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in update
190. bulk(self.conn, prepped_docs, index=self.index_name, doc_type='modelresult')
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/elasticsearch/helpers/init.py" in bulk
188. for ok, item in streaming_bulk(client, actions, **kwargs):
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/elasticsearch/helpers/init.py" in streaming_bulk
160. for result in _process_bulk_chunk(client, bulk_actions, raise_on_exception, raise_on_error, **kwargs):
File"/Users/MacbookAir/myproject/lib/python2.7/site-packages/elasticsearch/helpers/init.py" in _process_bulk_chunk
89. raise e

1
2
3
4
5
6
7
Exception Type: ConnectionError at /admin/items/country/add/
Exception Value: ConnectionError (<urllib3.connection.HTTPConnection
object at 0x111377110>: Failed to establish a new connection: [Errno
61] Connection refused) caused by:
NewConnectionError(<urllib3.connection.HTTPConnection object at
0x111377110>: Failed to establish a new connection: [Errno 61]
Connection refused)


这是一个问题,因为弹性搜索的安装不正确,我正在使用干草堆模块。 弹性搜索是使用Java构建的,并且至少需要Java 8才能运行。 一旦我安装了相同的,连接错误urllib3.connection.HTTPConnection就没问题了。


我假设您的数据库是本地托管的

因此,请尝试在数据库的设置文件中更改此设置

1
2
3
4
5
6
7
8
9
10
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mystic_db',
        'USER': 'root',
        'PASSWORD': '*****',
        'HOST': '127.0.0.1', or localhost whatever you prefer
        'PORT': '',
}
}