UnicodeDecodeError

UnicodeDecodeError

Postby NikosGr » Tue Jun 24, 2014 6:36 pm

Hello ppl,

Code: Select all
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')


As the error message says, the bytes given do not form a valid UTF-8 string. It seems something is outputting text in a different encoding to your website.


I tried decoding the bytes with the encodings I usually encounter but none of them produced anything recognizable. However, greek-8 seems to produce recognizable text:

Code: Select all
>>> b = b'\xb6\xe3\xed\xf9\xf3\xf4\xef \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2'
>>> b.decode('greek8')
'Άγνωστο όνομα συστήματος'



Code: Select all
root@secure [~]# tail /usr/local/apache/logs/error_log
[Tue Jun 24 19:45:22 2014] [error] [client 108.62.115.226]   File "/usr/local/lib/python3.4/os.py", line 651, in __getitem__
[Tue Jun 24 19:45:22 2014] [error] [client 108.62.115.226]     raise KeyError(key) from None
[Tue Jun 24 19:45:22 2014] [error] [client 108.62.115.226] KeyError: 'HTTP_COOKIE'
[Tue Jun 24 19:45:22 2014] [error] [client 108.62.115.226] Premature end of script headers: metrites.py
[Tue Jun 24 19:45:22 2014] [error] [client 108.62.115.226] File does not exist: /home/nikos/public_html/500.shtml
[Tue Jun 24 19:46:05 2014] [error] [client 2a02:214b:8106:9f00:35b3:3bca:f82e:89a9] Exception ignored in: <bound method Connection.__del__ of <pymysql.connections.Connection object at 0x7fb0cb8eb438>>, referer: http://superhost.gr/
[Tue Jun 24 19:46:05 2014] [error] [client 2a02:214b:8106:9f00:35b3:3bca:f82e:89a9] Traceback (most recent call last):, referer: http://superhost.gr/
[Tue Jun 24 19:46:05 2014] [error] [client 2a02:214b:8106:9f00:35b3:3bca:f82e:89a9]   File "/usr/local/lib/python3.4/site-packages/pymysql/connections.py", line 645, in __del__, referer: http://superhost.gr/
[Tue Jun 24 19:46:05 2014] [error] [client 2a02:214b:8106:9f00:35b3:3bca:f82e:89a9]   File "/usr/local/lib/python3.4/site-packages/pymysql/connections.py", line 632, in close, referer: http://superhost.gr/
[Tue Jun 24 19:46:05 2014] [error] [client 2a02:214b:8106:9f00:35b3:3bca:f82e:89a9] AttributeError: 'NoneType' object has no attribute 'pack', referer: http://superhost.gr/
root@secure [~]#


This is the code producing this:

Code: Select all
# retrieve cookie from client's browser otherwise set it
cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )
try:
   cookieID = cookie['ID'].value
except KeyError:
   cookieID = str( time.time() )
   cookieID = cookieID[-3:]

   cookie['ID'] = cookieID
   cookie['ID']['expires'] = 3600 * 24 * 100   # 1 year from now
   print( cookie.output() )   # send cookie to web client before headers[code]


Can you please tell me what exactly needs fixing so this error is no longer produced?
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest