加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

django无法连接到服务器:权限被拒绝服务器是否在主机上运行并接

发布时间:2020-12-20 12:27:25 所属栏目:Python 来源:网络整理
导读:我有一个奇怪的问题.我可以从命令行使用psql连接到远程主机,但不能在 django设置文件中使用完全相同的凭据.我收到错误: Could not connect to server: Permission denied Is the server running on host “remote ip” and accepting TCP/IP connections on
我有一个奇怪的问题.我可以从命令行使用psql连接到远程主机,但不能在 django设置文件中使用完全相同的凭据.我收到错误:

Could not connect to server: Permission denied Is the server running
on host “remote ip” and accepting TCP/IP connections on port
port_number?

如果我可以使用psql连接而不使用django我在这里缺少什么?我还检查了python解释器,我可以加载psycopg2.

任何帮助都非常感谢,因为我在网上找到的并没有帮助.

干杯,

d

这是settings.py中的db conf

'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2','NAME': '<db name goes here>',# Or path to database file if using sqlite3.
        'USER': '<db user>',# Not used with sqlite3.
        'PASSWORD': '<pswd goes here>',# Not used with sqlite3.
        'HOST': '<remote ip goes here>','PORT': '5432',}

解决方法

根据您的描述,这与Apache及其访问数据库的权限有关.您没有提到您使用的操作系统,但如果它正在运行SELinux,则默认规则会阻止apache连接到db.如果是这种情况,您可以通过运行以下命令暂时启用它:

setsebool httpd_can_network_connect_db

Here是更详细的说明.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读