vsemionov / django-blacklist Goto Github PK
View Code? Open in Web Editor NEWBlacklist users and hosts in Django. Automatically blacklist rate-limited clients.
License: MIT License
Blacklist users and hosts in Django. Automatically blacklist rate-limited clients.
License: MIT License
Hello
I have error after adding one rule
id 1
created 2021-03-31 21:56:33.792587
updated 2021-03-31 22:31:44.223164
address 196.245.0.0
prefix 16
duration 7900000000
user_id NULL
python3.8/site-packages/blacklist/middleware.py in _load_blacklist
for rule in rules:
Variable | Value
addr_blacklist | {}
current_time | datetime.datetime(2021, 3, 31, 22, 32, 57, 493809, tzinfo=)
rules | Error in formatting: AttributeError: 'str' object has no attribute 'tzinfo'
until | Max(F(created) + F(duration))
user_blacklist | {}
Can you help me?
Error:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 3.0.4
Python Version: 3.7.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_countries',
'languages',
'blacklist',
'taggit',
'user',
'model',
'administrator']
Installed 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',
'blacklist.middleware.blacklist_middleware']
Traceback (most recent call last):
File "D:\anaconda3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "D:\anaconda3\lib\site-packages\blacklist\middleware.py", line 40, in middleware
_load_blacklist()
File "D:\anaconda3\lib\site-packages\blacklist\middleware.py", line 98, in _load_blacklist
for rule in rules:
File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 276, in __iter__
self._fetch_all()
File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 115, in __iter__
for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1103, in results_iter
results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1138, in execute_sql
sql, params = self.as_sql()
File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 490, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 51, in pre_sql_setup
self.setup_query()
File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 42, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 257, in get_select
sql, params = self.compile(col)
File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 422, in compile
sql, params = node.as_sql(self, self.connection)
File "D:\anaconda3\lib\site-packages\django\db\models\aggregates.py", line 88, in as_sql
return super().as_sql(compiler, connection, **extra_context)
File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 633, in as_sql
arg_sql, arg_params = compiler.compile(arg)
File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 422, in compile
sql, params = node.as_sql(self, self.connection)
File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 448, in as_sql
return DurationExpression(self.lhs, self.connector, self.rhs).as_sql(compiler, connection)
File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 494, in as_sql
sql, params = self.compile(self.rhs, compiler, connection)
File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 484, in compile
return connection.ops.format_for_duration_arithmetic(sql), params
Exception Type: AttributeError at /admin/
Exception Value: 'DatabaseOperations' object has no attribute 'format_for_duration_arithmetic'
Perhaps of note: I am using djongo
How to use django-blacklist in class base view?
When I try to run the migration I get:
blacklist.Rule.user: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.
My settings.AUTH_USER_MODEL:
`AUTH_USER_MODEL = 'users.CustomUser' # Custom User Model
line 15 in blacklist/models.py needs updated to:
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE)
And from django.conf import settings
needs added to imports.
I can do a PR if you prefer.
Hello, thanks for your work on the plugin! Would it be possible to add in a setting variable to disable logging? When blacklisted IPs hit our endpoints repeatedly it leads to some spam in our logs. It would be great if we could just reject ip's silently. Thanks very much,
Steve
Hi there,
thanks a lot for this plugin! It has helped me a lot recently to reduce spam on my blog.
I'm hosting my app on Pythonanywhere. The issue is that they're changing the header of the requests slightly, so the real IP address of the client ends up under a different key, i.e. request.META.get('HTTP_X_REAL_IP')
, see their docs.
I was thinking about adding a setting, e.g. BLACKLIST_REMOTE_ADDR
, that would allow you to override the default header name (defaults to "REMOTE_ADDR"
). Would you be happy to review a PR? Many thanks!
Hi,
Can you describe with more detail, how to I pass the proxy server and add clients ip, not proxy ip?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.