Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53353
| From | Ferrous Cranus <nikos@superhost.gr> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: UnicodeDecodeError issue |
| Date | 2013-08-31 16:07 +0300 |
| Organization | GRNET - Greek Research and Technology Network |
| Message-ID | <kvsppn$nms$1@news.grnet.gr> (permalink) |
| References | (1 earlier) <mailman.403.1377933937.19984.python-list@python.org> <kvs7nj$dkn$1@news.grnet.gr> <kvs9kh$icu$1@news.grnet.gr> <5221d373$0$6599$c3e8da3$5496439d@news.astraweb.com> <kvsp94$n3d$1@news.grnet.gr> |
Στις 31/8/2013 3:58 μμ, ο/η Ferrous Cranus έγραψε:
> Στις 31/8/2013 2:28 μμ, ο/η Steven D'Aprano έγραψε:
>> On Sat, 31 Aug 2013 11:31:13 +0300, Ferrous Cranus wrote:
>>
>>> Here is the code inside files.py:
>>
>> The code you show is not the ENTIRE code inside of files.py, is it? You
>> are only showing us a small piece, correct?
>>
>> The code you show:
>>
>>> 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'] ) or
>>> socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] ) or
>>> os.environ['REMOTE_ADDR']
>>> except Exception as e:
>>> print( repr(e), file=open( '/tmp/err.out', 'w' ) )
>>
>>
>> does not contain a call to cur.execute. And here is your error:
>>
>>
>>> [error] [client 108.162.229.116] Traceback (most recent call last):,
>>> referer: http://superhost.gr/ [Sat Aug 31 08:29:33 2013] [error] [client
>>> 108.162.229.116] File "/home/nikos/public_html/cgi-bin/files.py", line
>>> 135, in <module>, referer: http://superhost.gr/
>>> [Sat Aug 31 08:29:33 2013] [error] [client 108.162.229.116]
>>> cur.execute('''INSERT INTO files (url, host, city, lastvisit) VALUES
>>> (%s, %s, %s, %s)''', (filename, host, city, lastvisit) ), referer:
>>> http://superhost.gr/
>>> [Sat Aug 31 08:29:33 2013] [error] [client 108.162.229.116] NameError:
>>> name 'host' is not defined, referer: http://superhost.gr/
>>
>>
>> Extracting out the critical part:
>>
>> line 135
>> cur.execute('''INSERT INTO files (url, host, city, lastvisit) VALUES
>> (%s, %s, %s, %s)''', (filename, host, city, lastvisit) ),
>>
>> Where is the call to cur.execute in the code snippet you show above?
>>
>>
>>
>>> But 'host' defaults to an ip address if it cannot resolve the hostname.
>>> Why the errro says its undefined?
>>
>> Because it is is undefined. Python is not lying to you. If Python tells
>> you there is an error, BELIEVE IT. Resolving the hostname is irrelevant.
>>
>> print(host) ### ERROR OCCURS HERE BECAUSE HOST IS UNDEFINED ###
>> host = socket.gethostbyaddr(addr)
> I'm not saying Python is lying of course it does not.
>
> But how is this possible since:
>
>
> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) or
> socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] ) or
> os.environ['REMOTE_ADDR']
>
>
> it must have a value by defaulting to something.
>
> The cur.execute fails because it make use of 'host' which is undefined.
>
> # Try to insert the file into the database
> cur.execute('''INSERT INTO files (url, host, city, lastvisit)
> VALUES (%s, %s, %s, %s)''', (filename, host, city, lastvisit) )
>
>
> And the question remain as to why 'host' is undefined.
Thsi fails too:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or
"Unkknown host"
--
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