META data differs between development runserver and Apache

45 views
Skip to first unread message

Moose Smith

unread,
Oct 7, 2022, 10:24:16 PM10/7/22
to Django users
I am a Django Newbie,

My problem is simple, when I run my code on the built in development server using Visual Studio Code on the server machine, my code works. When I run the same code on the same server using Apache the code fails. 

Specifically:
var1=(request.META)
var2=var1['LOGNAME']
or 
var2=var1['TZ']

IN both instances the name LOGNAME and TZ do not exist when the code is run on the apache server. (I get a Keyerror - does not exist) What must be happening is the data in var1 differs between the development server and apache.  

My question is why? I suspect it has something to do with WSGI?

Any clue will be greatly appriciated.

Moose
  

Mike Dewhirst

unread,
Oct 8, 2022, 3:46:48 AM10/8/22
to django...@googlegroups.com

-------- Original message --------
From: Moose Smith <47kan...@gmail.com>
Date: 8/10/22 13:24 (GMT+10:00)
To: Django users <django...@googlegroups.com>
Subject: META data differs between development runserver and Apache

I am a Django Newbie,

My problem is simple, when I run my code on the built in development server using Visual Studio Code on the server machine, my code works. When I run the same code on the same server using Apache the code fails. 

Specifically:
var1=(request.META)


print(var1) ... I typically insert print statements to see what is actually happening.



var2=var1['LOGNAME']
or 
var2=var1['TZ']

IN both instances the name LOGNAME and TZ do not exist when the code is run on the apache server. (I get a Keyerror - does not exist) What must be happening is the data in var1 differs between the development server and apache.  

My question is why? I suspect it has something to do with WSGI?

Any clue will be greatly appriciated.

Moose
  

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/795169b6-22f8-4ae8-8c3c-e7d71855b555n%40googlegroups.com.

Anh Nguyen

unread,
Oct 8, 2022, 4:45:21 AM10/8/22
to django...@googlegroups.com
Show all meta. Sound apache not pass this params

Moose Smith

unread,
Oct 8, 2022, 9:38:01 AM10/8/22
to Django users
Hello Everyone,

I have been digging into this problem and I have discovered the following. (Which is new to me as a newbie but maybe common knowledge to experienced users)
Regarding the  (request.META)  the request is an instance of HttpRequest class. When I looked this up in Django I found this:
____________________________________
HttpRequest.META

A dictionary containing all available HTTP headers. Available headers depend on the client and server, but here are some examples:

_______________________________

It states the available headers depend on the client AND server. SO when I run the code on the development runserver in visual studio code, it provides the LOGNAME and TZ (Time zone) but apparently apache does NOT. 

The question is why, and how can I fix this? I think I might be able to work around the LOGNAME but the timezone TZ is more difficult to figure out. 


ANY clues are appreciated,


Moose

Ryan Nowakowski

unread,
Oct 8, 2022, 10:38:38 AM10/8/22
to django...@googlegroups.com
It seems like runserver is picking up your shell environment variables and including them in request.META. Apache doesn't do that so you'll need to figure out a different way to get that info.

What are you using LOGNAME and TZ for? You can probably use Django's timezone support instead of TZ.

Moose Smith

unread,
Oct 8, 2022, 5:21:55 PM10/8/22
to Django users
Ryan is correct, it is picking up the shell environment variables.  I modified the code to write the VAR1 to a file on the server, and I was able to look at all the META variable and their values. Sure enough the LOGNAME and TZ do not appear but they are in my environment so now, as Ryan suspected, we know why this is happening.

The reason I need this data is because  my application allows users to take pictures with their phones, the pictures are USB download (for now) into a common directory and I have to try and match up the pictures with some other data that is entered into a database with a minute of the time the picture was taken. I use the user name (LOGNAME) and I need the timezone because the users are global, so I need to correct for the time stamp of the picture/database. I tried using UTC but that caused other issues and the users were getting confused.(too long to explain).

The LOGNAME I can get around that but, I see nothing in the META regarding timezone info. I assume (i'm a newbie) that I must use some additional code instead of request.META to get the timezone info. I will research....

Thanks for your help.

Moose
Reply all
Reply to author
Forward
0 new messages