Στις 1/9/2013 6:36 μμ, ο/η Dave Angel έγραψε:
On 1/9/2013 10:08, Ferrous Cranus wrote:

    <snip>
Here is it:


errout = open( '/tmp/err.out', 'w' )            # opens and truncates the error
output file
try:
        gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
        city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or
gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
        host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy
Detected"
except Exception as e:
        print( "Xyzzy exception-", repr( sys.exc_info() ), file=errout )
      errout.flush()

sys.exit(0)

and the output of error file is:


ni...@superhost.gr [~]# cat /tmp/err.out
UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef
\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1,
'invalid start byte')


Nope.  The label  "Xyzzy exception" is not in that file, so that's not
the file you created in this run.  Further, if that line existed before,
it would have been wiped out by the open with mode "w".

i suggest you add yet another write to that file, immediately after
opening it:

errout = open( '/tmp/err.out', 'w' )            # opens and truncates the error
print("starting run", file=errorout)
errout.flush()

Until you can reliably examine the same file that was logging your
errors, you're just spinning your wheels.  you might even want to write
the time to the file, so that you can tell whether it was now, or 2 days
ago that the run was made.




I tried it and it printed nothing.
But suddenly thw ebpage sttaed to run and i get n invalid byte entried and no weird messge files.py is working as expcted.
what on earht?

Now i ahve thso error:

# ================================================================================================================= # DATABASE INSERTS - do not increment the counter if a Cookie is set to the visitors browser already # ================================================================================================================= if( not vip and re.search( r'(msn|gator|amazon|yandex|reverse|cloudflare|who|fetch|barracuda|spider|google|crawl|pingdom)', host ) is None ):

        print( "i'm in and data is: ", host )
        try:
                #find the needed counter for the page URL
                if os.path.exists( path + page ) or os.path.exists( cgi_path + 
page ):
                        cur.execute('''SELECT ID FROM counters WHERE url = 
%s''', page )
                        data = cur.fetchone()           #URL is unique, so 
should only be one

                if not data:
                        #first time for page; primary key is automatic, hit is 
defaulted
                        cur.execute('''INSERT INTO counters (url) VALUES 
(%s)''', page )
                        cID = cur.lastrowid        #get the primary key value 
of the new record
                else:
                        #found the page, save primary key and use it to issue 
hit UPDATE
                        cID = data[0]
cur.execute('''UPDATE counters SET hits = hits + 1 WHERE ID = %s''', cID )

                #find the visitor record for the (saved) cID and current host
cur.execute('''SELECT * FROM visitors WHERE counterID = %s and host = %s''', (cID, host) )
                data = cur.fetchone()        #cID&host are unique
                        
                if not data:
                        #first time for this host on this page, create new 
record
cur.execute('''INSERT INTO visitors (counterID, host, city, useros, browser, lastvisit) VALUES (%s, %s, %s, %s, %s, %s)''', (cID, host, city, useros, browser, date) )
                else:
                        #found the page, save its primary key for later use
                        vID = data[0]
                        #UPDATE record using retrieved vID
cur.execute('''UPDATE visitors SET city = %s, useros = %s, browser = %s, hits = hits + 1, lastvisit = %s WHERE counterID = %s and host = %s''', (city, useros, browser, date, vID, host) )

                con.commit()            #if we made it here, the transaction is 
complete
                
        except pymysql.ProgrammingError as e:
                print( repr(e) )
                con.rollback()          #something failed, rollback the entire 
transaction
                sys.exit(0)


i get no counter increment when visitors visit my webpage.
What on eart is going on?

How the previous error with the invalid byte somehtign got solved?

--
Webhost <http://superhost.gr>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to