欢迎光临
我们一直在努力

python – ‘使用postgres和Gunicorn Nginx作为反向代理的Django app中的类型inet’db错误的输入语法无效

本站教程收集整理的这篇文章主要介绍了python – ‘使用postgres和Gunicorn Nginx作为反向代理的Django app中的类型inet’db错误的输入语法无效,本站教程本站觉得挺不错的,现在分享给大家,也给大家做个参考。

你能帮我解读这个相当深奥的错误吗?当我启动应用程序时,一切都很好,但在我尝试登录的那一刻崩溃了.

我知道inet data type接受IPv4和IPv6主机和网络(但不是域名)这一事实.

回溯如下:

TraceBACk:
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  187.                 response = middleware_method(request, responsE)
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/user_sessions/middleware.py" in process_response
  46.                     request.session.save()
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/user_sessions/BACkends/db.py" in save
  86.                     obj.save(force_insert=must_create, using=using)
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/base.py" in save
  546.                        force_update=force_update, update_fields=update_fields)
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  650.                 result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/manager.py" in _insert
  215.         return insert_query(self.model, objs, fields, **kwargs)
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/query.py" in insert_query
  1661.     return query.get_compiler(using=using).execute_sql(return_id)
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  937.             cursor.execute(sql, params)
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/BACkends/util.py" in execute
  41.             return self.cursor.execute(sql, params)
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/BACkends/POSTGResql_psycopg2/base.py" in execute
  58.             six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])
File "/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/BACkends/POSTGResql_psycopg2/base.py" in execute
  54.             return self.cursor.execute(query, args)

Exception Type: DatabaseError at /login/
Exception Value: invalid input Syntax for type inet: ""
LINE 1: ...00101 Firefox/41.0', '2015-12-12 09:39:55.590036+00:00', '')

urls.py中的/ login / url是url(r’^ login / $’,’django.contrib.auth.views.login’,{‘template_name’:’login.html’},name =“login”) ,

环境是:

Django 1.5.1带有POSTGResql后端并驻留在Ubuntu 14.04机器上.特别要注意的是,在我将Nginx设置为gunicorn后面的反向代理(使用端口80进行此设置)后,此错误开始出现.当我在端口8080上使用gunicorn(和女服务员,另一个纯python web服务器)时,事情很有效.

在/ etc / Nginx的/网站可用/ myproject的:

server {
    listen 80;
    server_name example.cloudapp.net;

    LOCATIOn = /favicon.ico { access_log off; log_not_found off; }
    LOCATIOn /static/ {
        root /home/mhb11/folder/myproject;
    }

    LOCATIOn / {
        include proxy_params;
        proxy_pass http://unix:/home/mhb11/folder/myproject/myproject.sock;
    }
   error_page 500 502 503 504 /500.html;
   LOCATIOn = /500.html {
        root /home/mhb11/folder/myproject/templates/;
   }
}

的/ etc / Nginx的/ proxy_params:

proxy_set_header Host $http_host;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-ForWARDed-For $proxy_add_x_forWARDed_for;
proxy_set_header X-ForWARDed-Proto $scheR_561_11845@e;

/etc/Nginx/Nginx.conf:

user www-data;
worker_processes 4;
pid /run/Nginx.pid;

env ON_AZURE=1;
env awsaccesskeyid=something;
env awssecretkey=something;

events {
        worker_connections 1024;
        multi_accept on;
        use epoll;
}

http {

        ##
        # Basic SetTings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        include /etc/Nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging SetTings
        ##

        access_log /var/log/Nginx/access.log;
        error_log /var/log/Nginx/error.log;

        ##
        # Gzip SetTings
        ##
        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+RSS text/javascrip$

 香港vps        ##
        # Nginx-naxsi config
        ##
        # Uncomment it if you installed Nginx-naxsi
        ##

        #include /etc/Nginx/naxsi_core.rules;

        ##
        # Nginx-passenger config
        ##
        # Uncomment it if you installed Nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/Nginx/conf.d/*.conf;
        include /etc/Nginx/sites-enabled/*;
}

#mail {
#       # See sample authentication script at:
#       # http://wiki.Nginx.org/ImapAuthenticateWithApachephpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIdplUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

这是怎么回事?

注意:如果您需要,请向我询问更多信息,例如:我的gunicorn.conf和Nginx.conf看起来如何,安装包或者你需要db相关的东西.请问!

解决方法:

您没有转发代理IP.这是我在Nginx配置中设置的转发标头集:

LOCATIOn / {
    proxy_set_header    Host                    $http_host;
    proxy_set_header    User-Agent              $http_user_agent;
    proxy_set_header    X-Real-IP               $remote_addr;
    proxy_set_header    X-ForWARDed-For         $proxy_add_x_forWARDed_for;
    proxy_set_header    X-ForWARDed-Proto       $scheR_561_11845@e;
    proxy_pass          ......;
}

Nginx docs中的更多选项 – http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header

然后在Django你可以这样做:

user_ip = request.Meta['http_X_REAL_IP`] or request.Meta['REMOTE_ADDR']

请注意,当使用带有SSL的Django时,X-ForWARDed-Proto是必需的,在这种情况下,您还需要稍微配置Django:

SECURE_PROXY_SSL_HEADER = ('http_X_FORWARDED_PROTO', 'https')

更多Django文档 – https://docs.djangoproject.com/en/1.9/ref/setTings/#std:setTing-SECURE_PROXY_SSL_HEADER

本站总结

以上是本站教程为你收集整理的python – ‘使用postgres和Gunicorn Nginx作为反向代理的Django app中的类型inet’db错误的输入语法无效全部内容,希望文章能够帮你解决python – ‘使用postgres和Gunicorn Nginx作为反向代理的Django app中的类型inet’db错误的输入语法无效所遇到的程序开发问题。

如果觉得本站教程网站内容还不错,欢迎将本站教程推荐给好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。