In test server it is working. But production gives this traceback:
what different? And what does that error mean?
Different is only in python versions. In test server it is 2.6.5 and production 2.5.2. How can I get rid of this error with out changing version?
True
2008-10-16 15:20:00
- did not match our database
Traceback (most recent call last):
File "./mr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/usr/local/cluster/dynamic/website/video/remmedia/management/commands/remmedia.py", line 50, in handle
self.FirstTimeLoad()
File "/usr/local/cluster/dynamic/website/video/remmedia/management/commands/remmedia.py", line 117, in FirstTimeLoad
med,created=RemMedia.objects.get_or_create(index=program.Id+50000000, defaults=fields)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/models/manager.py", line 123, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/models/query.py", line 335, in get_or_create
obj.save(force_insert=True)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/models/base.py", line 410, in save
self.save_base(force_insert=force_insert, force_update=force_update)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/models/base.py", line 495, in save_base
result = manager._insert(values, return_id=update_pk)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/models/manager.py", line 177, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/models/query.py", line 1087, in insert_query
return query.execute_sql(return_id)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/models/sql/subqueries.py", line 320, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/models/sql/query.py", line 2369, in execute_sql
cursor.execute(sql, params)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/django/db/backends/mysql/base.py", line 84, in execute
return self.cursor.execute(query, args)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/MySQLdb/cursors.py", line 158, in execute
query = query % db.literal(args)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/MySQLdb/connections.py", line 265, in literal
return self.escape(o, self.encoders)
File "/usr/local/cluster/dynamic/virtualenv/lib/python2.5/site-packages/MySQLdb/connections.py", line 198, in string_literal
return db.string_literal(obj)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-10: ordinal not in range(128)
After some time thinking and testing. I notice that error shows only when i do this:
med,created=RemMedia.objects.get_or_create(index=program.Id+50000000, defaults=fields)
After some more time of thinking end testing, i found the error. It is in dictionary fields. There is one variable which i get from BeautifulSoup the code looks like:
soup=BeautifulSoup(program.Description.encode('utf-8'))
name=soup.find('div',{'class':'head'})
fields=dict(
name=name.string,
description=program.Description.encode('utf-8'),
program_name=program.Name.encode('utf-8'),
program_date_time=program.RealDateTime,
topic_data_time=program.RealDateTime,
topic_tag='',
created=program.Updated,
media=media
)
The problem is with variable name in fields dictionary.
Question remain : How to convert it so it will not gives an error?
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-10: ordinal not in range(128)
Do you have a character with an ascii value > 128? Probably an accented letter.
http://www.asciitable.com/
If the problem lies within the database, it's probably a setting. If it's within the python code, you may try placing this line at the top of your python file that deals with the string.
# coding:utf-8
Related
Installations:
Windows 10, 64 bit.
Python 3.6.5
I am trying to execute pip install -r pyproj-1.9.6-cp36-cp36m-win_amd64.whl command.
However getting below error:
ERROR: Exception:
Traceback (most recent call last):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in _main
status = self.run(options, args)
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\cli\req_command.py", line 185, in wrapper
return func(self, options, args)
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\commands\install.py", line 302, in run
check_supported_wheels=not options.target_dir,
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\cli\req_command.py", line 341, in get_requirements
finder=finder, options=options, session=session):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 151, in parse_requirements
for parsed_line in parser.parse(filename, constraint):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 330, in parse
for line in self._parse_and_recurse(filename, constraint):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 335, in _parse_and_recurse
for line in self._parse_file(filename, constraint):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 369, in _parse_file
filename, self._session, comes_from=self._comes_from
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 574, in get_file_content
content = auto_decode(f.read())
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\utils\encoding.py", line 41, in auto_decode
locale.getpreferredencoding(False) or sys.getdefaultencoding(),
File "c:\users\sneka\appdata\local\programs\python\python36\lib\encodings\cp1252.py", line 15, in decode
return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 118: character maps to <undefined>
I am new to python and not able to solve this error. Please help.
Remove -r. It should be pip install pyproj-1.9.6-cp36-cp36m-win_amd64.whl
I am trying to return a file in a StreamingHttpResponse from a class based view using Django rest framework. However I get a very cryptic error message with a stack trace that does not contain any references to my code:
16/Jun/2017 11:08:48] "GET /api/v1/models/49 HTTP/1.1" 200 0
Traceback (most recent call last):
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/handlers.py", line 179, in finish_response
for data in self.result:
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/util.py", line 30, in __next__
data = self.filelike.read(self.blksize)
File "/Users/jonathan/anaconda/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 12: ordinal not in range(128)
[...]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/handlers.py", line 141, in run
self.handle_error()
File "/Users/jonathan/anaconda/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 88, in handle_error
super(ServerHandler, self).handle_error()
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/handlers.py", line 368, in handle_error
self.finish_response()
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/handlers.py", line 274, in write
self.send_headers()
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "/Users/jonathan/anaconda/lib/python3.6/wsgiref/handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
My get method looks like this:
def get(self, request, pk, format=None):
"""
Get model by primary key (pk)
"""
try:
model = QSARModel.objects.get(pk=pk)
except Exception:
raise Http404
filename = model.pluginFileName
chunk_size = 8192
response = StreamingHttpResponse(
FileWrapper( open(filename), chunk_size ),
content_type = 'application/zip' )
return response
From googling a bit I get the feeling that this is related to ASCII / UTF8 encoding but I don't understand how that applies to my situation. I am dealing with a binary file. In fact it is a Java jar file but that should be pretty much a zip file as far as I understand. What is going on here and what am I doing wrong?
this is related to language translation. when non ascii filenames with the django storage system. So add following lines in your apache envvars
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
https://code.djangoproject.com/wiki/django_apache_and_mod_wsgi#AdditionalTweaking
I've implemented a product called Odoo/OpenERP and recently performed a restart after changing some strings in multiple files.
These strings contained standard characters with no accented characters. After the restart, any access to the site results in the below:
2015-06-24 08:09:35,884 1584 ERROR XXXXXX-Odoo-Production werkzeug: Error on request:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/opt/odoo-production/openerp/service/server.py", line 290, in app
return self.app(e, s)
File "/opt/odoo-production/openerp/service/wsgi_server.py", line 216, in application
return application_unproxied(environ, start_response)
File "/opt/odoo-production/openerp/service/wsgi_server.py", line 202, in application_unproxied
result = handler(environ, start_response)
File "/opt/odoo-production/openerp/http.py", line 1290, in __call__
return self.dispatch(environ, start_response)
File "/opt/odoo-production/openerp/http.py", line 1264, in __call__
return self.app(environ, start_wrapped)
File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 579, in __call__
return self.app(environ, start_response)
File "/opt/odoo-production/openerp/http.py", line 1426, in dispatch
ir_http = request.registry['ir.http']
File "/opt/odoo-production/openerp/http.py", line 346, in registry
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
File "/opt/odoo-production/openerp/modules/registry.py", line 339, in get
update_module)
File "/opt/odoo-production/openerp/modules/registry.py", line 356, in new
registry = Registry(db_name)
File "/opt/odoo-production/openerp/modules/registry.py", line 60, in __init__
self._db = openerp.sql_db.db_connect(db_name)
File "/opt/odoo-production/openerp/sql_db.py", line 623, in db_connect
db, uri = dsn(to)
File "/opt/odoo-production/openerp/sql_db.py", line 614, in dsn
return db_or_uri, '%sdbname=%s' % (_dsn, db_or_uri)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 28: ordinal not in range(128)
I've checked the files I've made changes to, but these seem fine.
Does anyone know where I can start to debug this issue? I'm relatively new to Python and debugging/understanding this trace is something I'm not familiar with.
So you have to use unicode strings because when your string is processed, somewhere it needs to use it as unicode, and it fails because the string type is str. You can make it into unicode by
mystring = unicode(mystring, 'utf-8')
This will change the type of your string from str to unicode
I'm trying to do a mass import of data into an existing database. Sometimes the string fields in this other database contain strings that are larger than the field I'm importing them into. I'm OK with this, I'd like the system to just silently truncate, but I'm getting a warning which then also halts execution.
Since this is a live database, I'm running my code via "manage.py shell" and and when I call the import routine it halts after the first string field it encounters that's too long. Oddly it DOES insert it into the database truncated as I expect, but then exits the for loop.
Thanks!
Here's the error output:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/blah/blah/update.py", line 41, in updateCommunities
community.save()
File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 434, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 527, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "/usr/lib/pymodules/python2.6/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 1479, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 783, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 727, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line 15, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.6/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 168, in execute
if not self._defer_warnings: self._warning_check()
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 82, in _warning_check
warn(w[-1], self.Warning, 3)
Warning: Data truncated for column 'community_name' at row 1
I am trying to store some cryptographic data in couchdb. I need to store a salt and encrypted password in couchdb. The salt is generated using python's os.urandom(8) and the sample output of that would look like:
'z/\xfe\xdf\xdeJ=y'
I'm using python-couchdb api to store the document. When I try to save the document I get:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "build/bdist.macosx-10.7-intel/egg/couchdb/client.py", line 343, in __setitem__
status, headers, data = resource.put_json(body=content)
File "build/bdist.macosx-10.7-intel/egg/couchdb/http.py", line 499, in put_json
**params)
File "build/bdist.macosx-10.7-intel/egg/couchdb/http.py", line 514, in _request_json
headers=headers, **params)
File "build/bdist.macosx-10.7-intel/egg/couchdb/http.py", line 510, in _request
credentials=self.credentials)
File "build/bdist.macosx-10.7-intel/egg/couchdb/http.py", line 260, in request
body = json.encode(body).encode('utf-8')
File "build/bdist.macosx-10.7-intel/egg/couchdb/json.py", line 68, in encode
return _encode(obj)
File "build/bdist.macosx-10.7-intel/egg/couchdb/json.py", line 129, in <lambda>
dumps(obj, allow_nan=False, ensure_ascii=False)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 204, in encode
return ''.join(chunks)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 3: ordinal not in range(128)
Encode it as either base64 or as hex before saving, or save it in a binary field.
Encode the output of urandom in base 64 like this:
os.urandom(8).encode('base64')
As per the example in this thread