Cookie problems when accessing development server by name

12 views
Skip to first unread message

John Batty

unread,
Jul 25, 2008, 2:22:19 PM7/25/08
to Django users
I a Django virgin and am trying to get a sample development server up
and running on Linux.

I can run the Django server fine, and when I go to the admin URL I get
the admin logon page.
However, when I try to logon I get an error:
"Looks like your browser isn't configured to accept cookies. Please
enable cookies, reload this page, and try again".

This fails for both Safari and IE7 browsers.
Both browsers have cookies enabled (before you ask!).

However, if I access the server by IP address rather than name (http://
172.19.1.82:8080/admin/ rather than http://msd_pbtest:8080/admin/)
then I can login with no problems.

I'm starting to suspect it must be something to do with the hostname
configuration on my Linux server.
Any suggestions as to what could be misconfigured, or what could cause
this problem?

Django: 0.96.2
Server: CentOS5.1

[admin@msd_pbtest pestfvmon]$ python manage.py runserver
172.19.1.82:8080
Validating models...
0 errors found.

Django version 0.96.2, using settings 'pestfvmon.settings'
Development server is running at http://172.19.1.82:8080/
Quit the server with CONTROL-C.

[admin@msd_pbtest pestfvmon]$ uname -a
Linux msd_pbtest 2.6.18-53.1.14.el5.centos.plus #1 SMP Fri Mar 7
08:37:13 EST 2008 i686 i686 i386 GNU/Linux

[admin@msd_pbtest pestfvmon]$ more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

I originally had my hostname in /etc/hosts, but tried removing this as
I thought it might be causing the problem:
[admin@msd_pbtest pestfvmon]$ more /etc/hosts.original
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 msd_pbtest localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

[admin@msd_pbtest pestfvmon]$ host msd_pbtest
msd_pbtest.datcon.co.uk has address 172.19.1.82

[admin@msd_pbtest pestfvmon]$ ping msd_pbtest
PING msd_pbtest.datcon.co.uk (172.19.1.82) 56(84) bytes of data.
64 bytes from 172.19.1.82: icmp_seq=1 ttl=64 time=0.035 ms
64 bytes from 172.19.1.82: icmp_seq=2 ttl=64 time=0.048 ms

In settings.py I have:
...
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.middleware.doc.XViewMiddleware',
)
...
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'pestfvmon.pestfv',
)

Norman Harman

unread,
Jul 25, 2008, 3:28:27 PM7/25/08
to django...@googlegroups.com
John Batty wrote:
> I a Django virgin and am trying to get a sample development server up
> and running on Linux.
>
> I can run the Django server fine, and when I go to the admin URL I get
> the admin logon page.
> However, when I try to logon I get an error:
> "Looks like your browser isn't configured to accept cookies. Please
> enable cookies, reload this page, and try again".
>
> This fails for both Safari and IE7 browsers.
> Both browsers have cookies enabled (before you ask!).
>
> However, if I access the server by IP address rather than name (http://
> 172.19.1.82:8080/admin/ rather than http://msd_pbtest:8080/admin/)
> then I can login with no problems.
>
> I'm starting to suspect it must be something to do with the hostname
> configuration on my Linux server.
> Any suggestions as to what could be misconfigured, or what could cause
> this problem?


Maybe?
http://www.djangoproject.com/documentation/settings/#session-cookie-domain

msd_pbtest is not a FQDN which might be a problem. use
http://msd_pbtest.datcon.co.uk:8080/admin/ instead

and if you add msd_pbtest to your hosts use address 172.19.1.82 not
127.0.0.1

--
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___________________________________________________________________________
You've got fun! Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

John Batty

unread,
Jul 25, 2008, 5:08:49 PM7/25/08
to Django users
Norman

Many thanks for the suggestions - unfortunately none of them do the
trick.

I tried adding this line to my settings.py:
SESSION_COOKIE_DOMAIN = '.datcon.co.uk'
No difference.

Also tried accessing the page as: http://msd_pbtest.datcon.co.uk/admin/
No difference.

I may try snooping the HTTP traffic to see what is flowing in the
headers.

John

On Jul 25, 8:28 pm, "Norman Harman" <nhar...@statesman.com> wrote:
> John Batty wrote:
> > I a Django virgin and am trying to get a sample development server up
> > and running on Linux.
>
> > I can run the Django server fine, and when I go to the admin URL I get
> > the admin logon page.
> > However, when I try to logon I get an error:
> > "Looks like your browser isn't configured to accept cookies. Please
> > enable cookies, reload this page, and try again".
>
> > This fails for both Safari and IE7 browsers.
> > Both browsers have cookies enabled (before you ask!).
>
> > However, if I access the server by IP address rather than name (http://
> > 172.19.1.82:8080/admin/ rather thanhttp://msd_pbtest:8080/admin/)
> > then I can login with no problems.
>
> > I'm starting to suspect it must be something to do with the hostname
> > configuration on my Linux server.
> > Any suggestions as to what could be misconfigured, or what could cause
> > this problem?
>
> Maybe?http://www.djangoproject.com/documentation/settings/#session-cookie-d...

John Batty

unread,
Jul 27, 2008, 7:05:16 AM7/27/08
to Django users
I eventually figured out what the problem is - having an underscore
character in the hostname. Doh!

I found that Firefox worked fine, while IE7 and Safari both failed.
Looking at the HTTP flows, I could see Django supplying a cookie to
the browser, but the browser simply failed to return it on subsequent
requests.

Turns out that an underscore character is invalid within a domain name
according to RFC952.
If IE or Safari receives a cookie from a host with an underscore it
refuses to return it on subsequent requests.

See...
http://www-1.ibm.com/support/docview.wss?uid=swg21112062
http://www.ruby-forum.com/topic/151965

You live and learn...
Reply all
Reply to author
Forward
0 new messages