witam.
Mam taki kod:
import socket
import time
import os
greytime = 30 #sekundy greylist
float(greytime)
#--- greylista dla remote
def grey( sender ):
fileos = os.path.isfile('grey/'+sender)
if fileos:
file = open('grey/'+sender, 'r+')
tsfile = file.read()
tsfile.strip("\"")
tslocal = time.time()
gt = float(tslocal) - float(tsfile)
if gt >= greytime:
print "wieksze niz 300"
file.truncate(0)
newgt = gt - greytime
file.write(str(newgt))
else:
print "mniejsze niz 300"
file.close()
else:
ts = time.time()
file = open('grey/'+sender, 'w')
file.write(str(ts))
file.close()
return "action=defer_if_permit Service temporarily unavailable\n\n"
#-----------------------------------------------------
host = '127.0.0.1'
port = 2121
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(5)
while 1:
conn, addr = s.accept()
data = conn.recv(10240)
#-----------------------------------------------------
line = data.split("\n")
sender = "none" #--- sender
sasl = "none" #--- sasl username
for i in range(len(line)):
query = line[i].split("=")
if query[0] == "sender" and query[1] != "":
sender = query[1]
elif query[0] == "sasl_username" and query[1] != "":
sasl = query[1]
#-----------------------------------------------------
#--- lokalny
if sasl != "none" and sender == sasl:
print "lokalny"
#--- podszycie
elif sasl != "none" and sender != sasl:
print "impersonation -"+" sasl="+sasl+" sender="+sender
conn.send("action=reject incorrect sender email address\n\n")
#--- remote
elif sasl == "none":
# print "ppp"
grey(sender)
#--- domyslna akcja
else:
conn.send("action=dunno\n\n")
conn.send("action=dunno\n\n") #--- zahaszowac gdy skrypt gotowy
#-----------------------------------------------------
dostaję taki komunikat:
root@ovh:/etc/postfix/limit# python -W all limit.py
Traceback (most recent call last):
File "limit.py", line 87, in <module>
grey(sender)
File "limit.py", line 22, in grey
gt = float(tslocal) - float(tsfile)
ValueError: could not convert string to float:
w czym może być problem ?
tutaj jest coś nie tak ---> gt = float(tslocal) - float(tsfile)
tak mi się wydaje
dane z pliku jakie pobiera skrypt to timestamp (bez znaku nowej linii):
root@ovh:/etc/postfix/limit/grey# cat joszi1980@interia.pl
70.2338929176root@ovh:/etc/postfix/limit/grey#