Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53437
| From | Ferrous Cranus <nikos@superhost.gr> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: UnicodeDecodeError issue |
| Date | 2013-09-02 01:23 +0300 |
| Organization | National Technical University of Athens, Greece |
| Message-ID | <l00epm$1ce3$1@news.ntua.gr> (permalink) |
| References | (1 earlier) <ce40cfed-978b-41d6-9fca-c1a9d54855cf@googlegroups.com> <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <kvvhoi$1v4o$1@news.ntua.gr> <mailman.450.1378049809.19984.python-list@python.org> <kvvoua$2ifa$1@news.ntua.gr> |
Στις 1/9/2013 7:10 μμ, ο/η Ferrous Cranus έγραψε:
> Στις 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:
>>>
>>>
>>> nikos@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?
>
i still wonder how come the invalid byte messge dissapeared
--
Webhost <http://superhost.gr>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 09:41 +0300
Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-08-31 16:53 +1000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 10:02 +0300
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 10:18 +0300
Re: UnicodeDecodeError issue Peter Otten <__peter__@web.de> - 2013-08-31 09:25 +0200
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 10:58 +0300
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 11:31 +0300
Re: UnicodeDecodeError issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 11:28 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 15:58 +0300
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-08-31 16:07 +0300
Re: UnicodeDecodeError issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 15:44 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-08-31 23:50 -0700
Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-01 17:12 +1000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 10:23 +0300
Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-01 17:28 +1000
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-01 10:35 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 16:59 +0300
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-01 15:40 +0000
Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-01 20:51 +1000
Re: UnicodeDecodeError issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-01 08:35 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 17:08 +0300
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 17:25 +0300
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-01 15:36 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-01 19:10 +0300
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-02 01:23 +0300
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-01 23:14 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-02 07:16 +0300
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-02 11:38 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-02 14:49 +0300
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-02 12:21 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-02 18:05 +0300
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-02 18:28 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-09-04 01:35 -0700
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-04 11:26 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-04 14:38 +0300
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-04 12:38 +0000
Re: UnicodeDecodeError issue Ferrous Cranus <nikos@superhost.gr> - 2013-09-04 17:29 +0300
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-05 00:17 +0000
Re: UnicodeDecodeError issue Steven D'Aprano <steve@pearwood.info> - 2013-09-05 03:07 +0000
Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-05 13:59 +1000
Re: UnicodeDecodeError issue Steven D'Aprano <steve@pearwood.info> - 2013-09-05 05:28 +0000
Re: UnicodeDecodeError issue MRAB <python@mrabarnett.plus.com> - 2013-09-02 12:56 +0100
Re: UnicodeDecodeError issue Dave Angel <davea@davea.name> - 2013-09-02 12:24 +0000
Re: UnicodeDecodeError issue MRAB <python@mrabarnett.plus.com> - 2013-09-02 15:44 +0100
Re: UnicodeDecodeError issue wxjmfauth@gmail.com - 2013-09-03 08:23 -0700
Re: UnicodeDecodeError issue Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-04 10:01 +0200
Re: UnicodeDecodeError issue wxjmfauth@gmail.com - 2013-09-04 07:08 -0700
Re: UnicodeDecodeError issue Chris Angelico <rosuav@gmail.com> - 2013-09-03 08:45 +1000
Re: UnicodeDecodeError issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-03 14:56 +0000
Re: UnicodeDecodeError issue Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-02 20:49 -0400
csiph-web