Thanks again Julian
i tried the syntax that you have given, but this does not solves our
problem
This is the error now i m getting when i use csv_file =
self.request.get('file1').decode('utf-8')
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/
webapp/__init__.py", line 702, in _call_
handler.post(*groups)
File "/base/data/home/apps/appsarp56/12.351609311322083742/csv123.py",
line 183, in post
csv_file = self.request.get('file1').decode('utf-8')
File "/base/python_runtime/python_dist/lib/python2.5/encodings/
utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position
164-165: invalid data
Please suggest me any way to read the unicode data from the CSV file
in python 2.5.
Regards
Prakhil
> You need to do the convertion tounicodebefore any split or strip,
> try
> csv_file = self.request.get('file1').decode('utf-8') on your first
> line or if it is urlencoded:
> csv_file = urllib.unquote( self.request.get('file1') ).decode('utf-8')
>
> On Jul 1, 3:45 pm, prakhil samar <
prakhilsa...@gmail.com> wrote:
>
>
>
> > Hi Julian,
>
> > Thanks for your information.
>
> > I am trying to upload a CSV file which contains some special
> > characters (Unicodecharacters which are not in the ASCII range). The
> > following is the data which the CSV file contains:
>
> > Name Address City
> > Country State Zip Cde Region
> > à á â 5334 Swenson Avenue New York United States of America
> > California 12345 North America
>
> > I am using the following Code for reading the data from HTML and
> > process the data in CSV file:
>
> > HTML page:
> > <input type='file' name="file1" id="idfileupload” />
>
> > Myfile.py:
> > csv_file = self.request.get('file1')
> > csv_reader = unicode_csv_reader(csv_file)
> > fileReader=csv.reader(csv_file.split("\r
> > \n"),skipinitialspace=True,quotechar='"',quoting=csv.QUOTE_MINIMAL)
> > for reader in fileReader:
> > for read in reader:
> > r = read.strip()
> > r =unicode(r, 'utf-8')
> > <process the data>
>
> > Now, when I try to upload the file, I am getting the following error:”
>
> > “ UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position
> > 0: ordinal not in range(128) “
>
> > What I understood is, After reading the data from CSV file, I am
> > getting a 2 byte string in variable "read" in the above code. and as
> > per my understanding we cannot convert 2 bytes string tounicodeso it
> > is giving the above error
>
> > I also tried, decode() and encode() methods. I am getting the same
> > error.
>
> > Please help me out, to read the data from CSV file and convert that to
> >Unicodeand upload in the database?