django-cookie-consent icon indicating copy to clipboard operation
django-cookie-consent copied to clipboard

Readme update to add settings.py params required to install and use the app

Open nicktgr15 opened this issue 4 years ago • 7 comments

nicktgr15 avatar Jun 23 '20 23:06 nicktgr15

@nicktgr15 this two settings should already have defaults as set in https://github.com/bmihelac/django-cookie-consent/blob/master/cookie_consent/conf.py#L10-L11

Does it not work for you without this settings?

bmihelac avatar Jun 24 '20 05:06 bmihelac

FYI: COOKIE_CONSENT_NAME with a bytes value breaks on modern installations. So it doesn't work without setting this explicitly in the settings.py No complaints on COOKIE_CONSENT_MAX_AGE

JesseDeLoore avatar Mar 21 '21 14:03 JesseDeLoore

@bmihelac Same as what @JesseDeLoore said. I'm getting TypeError: cannot use a string pattern on a bytes-like object on Django==3.1.7 until I set the name as a string in settings.

web_1  |   File "/usr/local/lib/python3.7/site-packages/cookie_consent/views.py", line 53, in post
web_1  |     self.process(request, response, varname)
web_1  |   File "/usr/local/lib/python3.7/site-packages/cookie_consent/views.py", line 63, in process
web_1  |     accept_cookies(request, response, varname)
web_1  |   File "/usr/local/lib/python3.7/site-packages/cookie_consent/util.py", line 98, in accept_cookies
web_1  |     set_cookie_dict_to_response(response, cookie_dic)
web_1  |   File "/usr/local/lib/python3.7/site-packages/cookie_consent/util.py", line 43, in set_cookie_dict_to_response
web_1  |     settings.COOKIE_CONSENT_MAX_AGE)
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/http/response.py", line 169, in set_cookie
web_1  |     self.cookies[key] = value
web_1  |   File "/usr/local/lib/python3.7/http/cookies.py", line 495, in __setitem__
web_1  |     self.__set(key, rval, cval)
web_1  |   File "/usr/local/lib/python3.7/http/cookies.py", line 485, in __set
web_1  |     M.set(key, real_value, coded_value)
web_1  |   File "/usr/local/lib/python3.7/http/cookies.py", line 351, in set
web_1  |     if not _is_legal_key(key):
web_1  | TypeError: cannot use a string pattern on a bytes-like object

motasay avatar Apr 09 '21 13:04 motasay

I understand, it looks like that default value should be string and not bytestring. Like removing b here: https://github.com/bmihelac/django-cookie-consent/blob/master/cookie_consent/conf.py#L10

bmihelac avatar Apr 14 '21 06:04 bmihelac

@JesseDeLoore and @motasay Can you tell us how we could recreate this error ourselves?

some1ataplace avatar Mar 13 '22 05:03 some1ataplace

@JesseDeLoore and @motasay Can you tell us how we could recreate this error ourselves?

The error happened when I didn't put a value for COOKIE_CONSENT_NAME and the default with a bytes value was used. Since this issue is a little older now maybe it is resolved on the python side.

As a point of order: is there a specific reason the default value uses a byte-string ?

JesseDeLoore avatar Mar 13 '22 07:03 JesseDeLoore

@JesseDeLoore Thank you. This error still occurs if you do not set a value for COOKIE_CONSENT_NAME in your own settings.py and the default is used instead.

some1ataplace avatar Mar 13 '22 20:03 some1ataplace