strange test for None

  • Thread starter karoly.kiripolszky
  • Start date
K

karoly.kiripolszky

in my server i use the following piece of code:

ims = self.headers["if-modified-since"]
if ims != None:
t = int(ims)

and i'm always getting the following error:

t = int(ims)
ValueError: invalid literal for int(): None

i wanna know what the hell is going on... first i tried to test using
is not None, but it makes no difference.
 
R

rzed

in my server i use the following piece of code:

ims = self.headers["if-modified-since"]
if ims != None:
t = int(ims)

and i'm always getting the following error:

t = int(ims)
ValueError: invalid literal for int(): None

i wanna know what the hell is going on... first i tried to test
using is not None, but it makes no difference.

It appears that ims is the string 'None', so it fails the test, but
is an invalid literal.
 
M

Michael Bentley

in my server i use the following piece of code:

ims = self.headers["if-modified-since"]
if ims != None:
t = int(ims)

and i'm always getting the following error:

t = int(ims)
ValueError: invalid literal for int(): None

i wanna know what the hell is going on... first i tried to test using
is not None, but it makes no difference.

Sounds like ims == 'None'. Try changing:

if ims != None:

to

if ims:

and you might also wrap your call to int(ims) in a try block.

HTH,
Michael
 
K

karoly.kiripolszky

the tested variable was really a string containing "None" instead of
simply None. this is the first time i ran into this error message
confusion. :)

thanks for the help!

in my server i use the following piece of code:
ims = self.headers["if-modified-since"]
if ims != None:
t = int(ims)
and i'm always getting the following error:
t = int(ims)
ValueError: invalid literal for int(): None
i wanna know what the hell is going on... first i tried to test using
is not None, but it makes no difference.

Sounds like ims == 'None'. Try changing:

if ims != None:

to

if ims:

and you might also wrap your call to int(ims) in a try block.

HTH,
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top