gpt4 book ai didi

python - 中间件: 'WSGIRequest' object has no attribute 'get'

转载 作者:行者123 更新时间:2023-12-01 05:14:49 26 4
gpt4 key购买 nike

我尝试使用中间件请求访问IP地址,这是我的示例代码,

def process_request(self, request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[-1].strip()
else:
ip = request.META.get('REMOTE_ADDR') --> I am getting the error here
return ip

这是我完整的错误跟踪:

Environment:

Request Method: GET
Request URL: http://localhost/admin/management/banipaddress/

Django Version: 1.6.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'utils',
'catalog',
'preview',
'cart',
'management')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'custom.middleware.banipmiddleware.BanIpMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/home/user/prodjango-env/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
201. response = middleware_method(request, response)
File "/home/user/prodjango-env/venv/local/lib/python2.7/site-packages/django/middleware/clickjacking.py" in process_response
30. if response.get('X-Frame-Options', None) is not None:

Exception Type: AttributeError at /admin/management/banipaddress/
Exception Value: 'WSGIRequest' object has no attribute 'get'

最佳答案

错误似乎在另一行

File "/home/user/prodjango-env/venv/local/lib/python2.7/site-packages/django/middleware/clickjacking.py" in process_response
30. if response.get('X-Frame-Options', None) is not None:

clickjacking.py中。

不知道它是你的。尝试访问不正确的 response.get()

关于python - 中间件: 'WSGIRequest' object has no attribute 'get' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23422392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com