Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'subject:Python': 0.06; 'skip:" 60': 0.07; 'ascii': 0.09; 'encode': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '(name,)': 0.16; '122,': 0.16; 'codec': 0.16; 'execute,': 0.16; 'ordinal': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'storing': 0.16; 'subject:issue': 0.16; 'url:py': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'appears': 0.22; 'manual': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'header': 0.24; 'query': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'correct': 0.29; 'characters': 0.30; 'code': 0.31; 'that.': 0.31; 'skip:= 20': 0.31; 'skip:q 20': 0.31; 'file': 0.32; '(most': 0.33; 'subject: (': 0.35; "can't": 0.35; 'info': 0.35; 'list': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'address.': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'subject: ': 0.61; 'received:173': 0.61; 'name': 0.63; 'url :cgi-bin': 0.65; 'of:': 0.68; 'money': 0.72; 'received:fios.verizon.net': 0.84; 'skip:/ 30': 0.84; 'whereas': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Jan Reedy Subject: Re: Encodign issue in Python 3.3.1 (once again) Date: Sun, 26 May 2013 16:53:56 -0400 References: <7823093c-2c07-4fa0-ae97-960c62f8ff9d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: <7823093c-2c07-4fa0-ae97-960c62f8ff9d@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369601640 news.xs4all.nl 15993 [2001:888:2000:d::a6]:38256 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46119 On 5/26/2013 12:36 PM, Νίκος Γκρ33κ wrote: > This is the code that although correct becaus it works with englisg(standARD ASCII letters) it wont with Greek: > > if( log ): > name = log > # print specific client header info > cur.execute('''SELECT hits, money FROM clients WHERE name = %s''', (name,) ) > data = cur.fetchone() > ======================= > > The following is the live output of: tail -F /usr/local/apache/logs/error_log & > > > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Error in sys.excepthook:, referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] UnicodeEncodeError: 'ascii' codec can't encode characters in position 2050-2056: ordinal not in range(128), referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] , referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Original exception was:, referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Traceback (most recent call last):, referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] File "pelatologio.py", line 122, in , referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] cur.execute('''SELECT hits, money FROM clients WHERE name = %s''', (name,) ), referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] File "/opt/python3/lib/python3.3/site-packages/pymysql/cursors.py", line 108, in execute, referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] query = query.encode(charset), referer: http://superhost.gr/cgi-bin/pelatologio.py > [Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] UnicodeEncodeError: 'latin-1' codec can't encode characters in position 46-52: ordinal not in range(256), referer: http://superhost.gr/cgi-bin/pelatologio.py This appears to be an issue with your mysql database and how you set it up.. It is using charset='latin-1' whereas you need it to consistently use charset='utf8' both for storing strings and for retrieval. Check the mysql manual or ask on a mysql list for how to do that. I have no idea so don't ask me, or send mail to my emall address.