0

I have an upload html form:

<form method="post" enctype="multipart/form-data" action="{{ upload_url }}">
    <input type="file" id="import_groups_csv" name="import_groups_csv">
    <input type="submit" value="Import groups">
</form>

And this is the class that read the file from blobstore:

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload_files = self.get_uploads('import_groups_csv')  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        file = blobstore.get(blob_info.key()).open().read()
        for line in file:
            logging.info("line *******************"+str(line))
        self.redirect('/groups')

When the file is uploaded i want to read every line on it but with this i git already an Error and this is traceback:

INFO     2014-08-04 13:47:04,252 views.py:332] line *******************ERROR    2014-08-04 13:47:04,255 traceback.py:13] Traceback (most recent call last):

ERROR    2014-08-04 13:47:04,256 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\app_logging.py", line 78, in emit

ERROR    2014-08-04 13:47:04,256 traceback.py:13]     logservice.write(message)

ERROR    2014-08-04 13:47:04,256 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice.py", line 347, in write

ERROR    2014-08-04 13:47:04,256 traceback.py:13]     logs_buffer().write(message)

ERROR    2014-08-04 13:47:04,256 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice.py", line 236, in write

ERROR    2014-08-04 13:47:04,256 traceback.py:13]     return self._lock_and_call(self._write, line)

ERROR    2014-08-04 13:47:04,256 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice.py", line 157, in _lock_and_call

ERROR    2014-08-04 13:47:04,256 traceback.py:13]     return method(*args)

ERROR    2014-08-04 13:47:04,256 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice.py", line 253, in _write

ERROR    2014-08-04 13:47:04,256 traceback.py:13]     self._autoflush()

ERROR    2014-08-04 13:47:04,256 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice.py", line 321, in _autoflush

ERROR    2014-08-04 13:47:04,256 traceback.py:13]     self._flush()

ERROR    2014-08-04 13:47:04,256 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice.py", line 307, in _flush

ERROR    2014-08-04 13:47:04,256 traceback.py:13]     apiproxy_stub_map.MakeSyncCall('logservice', 'Flush', request, response)

ERROR    2014-08-04 13:47:04,256 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 94, in MakeSyncCall

ERROR    2014-08-04 13:47:04,256 traceback.py:13]     return stubmap.MakeSyncCall(service, call, request, response)

ERROR    2014-08-04 13:47:04,257 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 320, in MakeSyncCall

ERROR    2014-08-04 13:47:04,257 traceback.py:13]     rpc.CheckSuccess()

ERROR    2014-08-04 13:47:04,257 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_rpc.py", line 156, in _WaitImpl

ERROR    2014-08-04 13:47:04,257 traceback.py:13]     self.request, self.response)

ERROR    2014-08-04 13:47:04,257 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub.py", line 123, in MakeSyncCall

ERROR    2014-08-04 13:47:04,257 traceback.py:13]     method(request, response, request_id)

ERROR    2014-08-04 13:47:04,257 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice_stub.py", line 182, in _Dynamic_Flush

ERROR    2014-08-04 13:47:04,257 traceback.py:13]     self._insert_app_logs(request_id, group.log_line_list())

ERROR    2014-08-04 13:47:04,257 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub.py", line 160, in WrappedMethod

ERROR    2014-08-04 13:47:04,259 traceback.py:13]     return method(self, *args, **kwargs)

ERROR    2014-08-04 13:47:04,259 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice_stub.py", line 193, in _insert_app_logs

ERROR    2014-08-04 13:47:04,259 traceback.py:13]     '(?, ?, ?, ?)', new_app_logs)

ERROR    2014-08-04 13:47:04,259 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice_stub.py", line 190, in <genexpr>

ERROR    2014-08-04 13:47:04,259 traceback.py:13]     for log_line in log_lines)

ERROR    2014-08-04 13:47:04,259 traceback.py:13]   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\logservice\logservice_stub.py", line 200, in _tuple_from_log_line

ERROR    2014-08-04 13:47:04,259 traceback.py:13]     message = message.decode('utf-8')

ERROR    2014-08-04 13:47:04,259 traceback.py:13]   File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode

ERROR    2014-08-04 13:47:04,259 traceback.py:13]     return codecs.utf_8_decode(input, errors, True)

ERROR    2014-08-04 13:47:04,259 traceback.py:13] UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 27: invalid start byte

ERROR    2014-08-04 13:47:04,259 app_logging.py:82] Logged from file views.py, line 332

i have followed as specified in google developper for this, but it's poorly documented. any idea of the root cause ?

2
  • I take it that self.get_uploads actually writes the uploaded file to the blobstore? Can you log its blob_info.key() to make sure? Which is line 332 in views.py? If your template file save in UTF-8 format? Commented Aug 4, 2014 at 14:57
  • @GAEfan: i have log the str(blob_info.key()) gave me this : ifeaztEIMug6_bJzv9sNpw== and the line 332 in my views file is self.redirect('/groups') Commented Aug 4, 2014 at 15:22

1 Answer 1

1

Place this as the top line in your views.py:

# -*- coding: utf-8 -*-

And, make sure that views.py is saved in UTF-8 format. Depending in your text editor, go to Save As, and make sure it is Unicode, and not ASCII.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.