robogals / myrobogals

myRobogals is the global intranet and record-keeping tool for Robogals. It has been built to simplify many of our day-to-day tasks including organising school visits, maintaining a member database, communicating with members, storing records reliably for future generations and easily collecting statistics on a global scale.
https://my.robogals.org
10 stars 21 forks source link

Japanese characters can't be exported from member list #38

Closed U-238 closed 11 years ago

U-238 commented 11 years ago

Description of problem: Names containing non-ASCII characters cause an error when trying to export

Location of problem: https://my.robogals.org/chapters/tokyo/edit/users/export/?status=1

Traceback (most recent call last):

File "/usr/local/django1.3.1/django/core/handlers/base.py", line 111, in get_response response = callback(request, _callback_args, *_callback_kwargs)

File "/home/myrobogals/robogals/myrobogals/auth/decorators.py", line 78, in call return self.view_func(request, _args, *_kwargs)

File "/home/myrobogals/robogals/myrobogals/rgprofile/views.py", line 1080, in exportusers writer.writerow([user['userusername'], user['userfirst_name'], user['userlast_name'], user['useremail'], user['usermobile'], user['usercourse'], user['useruniversityname'], user['userstudent_number'], user['useralt_email'], user['userdate_joined'], user['userdob'], user['usergender'], user['user__uni_start'], user['useruni_end'], user['user__course_type'], user['user__student_type']])

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

<WSGIRequest GET:<QueryDict: {u'status': [u'1']}>, POST:<QueryDict: {}>, COOKIES:{'utma': '225450521.1214822885.1351063476.1351063476.1351063476.1', 'utmb': '225450521.1.10.1351063476', 'utmc': '225450521', 'utmz': '225450521.1351063476.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', 'sessionid': '75f9db292eaeccbe4e6336c647812d33'}, META:{'DOCUMENT_ROOT': '/home/myrobogals/blank/', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTPS': '1', 'HTTPACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,/_;q=0.8', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate', 'HTTP_ACCEPT_LANGUAGE': 'en-us', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'sessionid=75f9db292eaeccbe4e6336c647812d33; utma=225450521.1214822885.1351063476.1351063476.1351063476.1; utmb=225450521.1.10.1351063476; utmc=225450521; utmz=225450521.1351063476.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', 'HTTP_HOST': 'my.robogals.org', 'HTTP_PROXY_CONNECTION': 'keep-alive', 'HTTP_REFERER': 'https://my.robogals.org/chapters/tokyo/edit/users/', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14', 'PATH_INFO': u'/chapters/tokyo/edit/users/export/', 'PATH_TRANSLATED': '/home/myrobogals/robogals/wsgi/myrobogals.wsgi/chapters/tokyo/edit/users/export/', 'QUERY_STRING': 'status=1', 'REMOTE_ADDR': '131.112.125.216', 'REMOTE_PORT': '38353', 'REQUEST_METHOD': 'GET', 'REQUEST_URI': '/chapters/tokyo/edit/users/export/?status=1', 'SCRIPT_FILENAME': '/home/myrobogals/robogals/wsgi/myrobogals.wsgi', 'SCRIPT_NAME': u'', 'SERVER_ADDR': '10.1.1.220', 'SERVER_ADMIN': 'my@robogals.org', 'SERVER_NAME': 'my.robogals.org', 'SERVER_PORT': '443', 'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_SIGNATURE': '

Apache/2.2.9 (Debian) Phusion_Passenger/2.2.11 PHP/5.3.6-13 with Suhosin-Patch mod_ruby/1.2.6 Ruby/1.8.7(2011-02-18) mod_ssl/2.2.9 OpenSSL/0.9.8o mod_wsgi/3.3 Python/2.6.6 mod_perl/2.0.5 Perl/v5.14.2 Server at my.robogals.org Port 443
\n', 'SERVER_SOFTWARE': 'Apache/2.2.9 (Debian) Phusion_Passenger/2.2.11 PHP/5.3.6-13 with Suhosin-Patch mod_ruby/1.2.6 Ruby/1.8.7(2011-02-18) mod_ssl/2.2.9 OpenSSL/0.9.8o mod_wsgi/3.3 Python/2.6.6 mod_perl/2.0.5 Perl/v5.14.2', 'mod_wsgi.application_group': 'my.robogals.org|', 'mod_wsgi.callable_object': 'application', 'mod_wsgi.handler_script': '', 'mod_wsgi.input_chunked': '0', 'mod_wsgi.listener_host': '', 'mod_wsgi.listener_port': '443', 'mod_wsgi.process_group': '', 'mod_wsgi.request_handler': 'wsgi-script', 'mod_wsgi.script_reloading': '1', 'mod_wsgi.version': (3, 3), 'wsgi.errors': <mod_wsgi.Log object at 0xa4b62c8>, 'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0xa3ca770>, 'wsgi.input': <mod_wsgi.Input object at 0xa4537c8>, 'wsgi.multiprocess': True, 'wsgi.multithread': False, 'wsgi.run_once': False, 'wsgi.url_scheme': 'https', 'wsgi.version': (1, 1)}>

yfcheung commented 11 years ago

The solution seems a bit illusional.

I saw some posts with the following comment regarding the solution: "Like the stars in the sky, seems so close, until I actually want to reach it by rising my arm!"

I will keep looking.

U-238 commented 11 years ago

Using this error message from above I think the problem is with unicode characters: "UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)"

Some things I found online about using CSV files with unicode output. http://docs.python.org/2/library/csv.html#csv-examples http://stackoverflow.com/questions/5838605/python-dictwriter-writing-utf-8-encoded-csv-files

Hopefully that helps

U-238 commented 11 years ago

Merged and tested!