I am using Flask-RESTful for building REST api and webargs for parsing.
While defining resource, I want argument to be present, so I wrote required=True
For example:
class Name(Resource):
"""Retrieve ids corresponding to given names
Input entries: String
"""
args = {
'entries' : fields.Str(required=True),
}
#use_kwargs(args)
def get(self, entries):
# HTTP method GET
result = object.find_id(entries)
return jsonify(result)
now,
While performing unittesting for API, explicitly not specifying entries, it returns Assertion Error
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 268, in error_router
return self.handle_error(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1363, in handle_user_exception
assert exc_value is e
AssertionError
When I checked, exc_value is
TypeError("ValidationError({'entries': [u'Missing data for required field.']}, status_code=422, headers={}) is not JSON serializable",)
and e is
<UnprocessableEntity '422: Unprocessable Entity'>
Now,
I've these ways to handle this exception
#app.errorhandler(500)
#app.errorhandler(ValidationError)
#app.errorhandler(TypeError)
#app.errorhandler(UnprocessableEntity)
#app.errorhandler(422)
#app.errorhandler(Exception)
I don't know why even this is not working
#app.errorhandler(AssertionError)
Refered to this:
link
but wasn't able to solve
I am using
Flask(0.10.1)
Flask-Restful(0.3.5)
webargs(1.2.0)
I have hit this issue only today (even though I have been using Flask-RESTplus for almost a year now), and it came as a weird discovery. I see this issue only with Python 2.7 while Python 3.3, 3.4, 3.5 work fine.
Thus, I think it should be considered as a compatibility bug in either webargs or Flask, I'm not sure yet.
UPDATE: After some digging into the issue, I ended up in webargs and filed an issue with my troubleshooting there: https://github.com/sloria/webargs/issues/122
UPDATE 2: Here is my PR fixing this issue: https://github.com/sloria/webargs/pull/123
Related
My code for the PUT method,
#app.route('/update_doc/<id>', methods=["PUT"])
def update_method(id):
body = request.get_json()
updated_document = db_collection.objects.get(id=id).update(**body)
#document.modify(**body)
return 'success', 200
I am getting the following error,
Traceback (most recent call last):
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 2088, in __call__
return self.wsgi_app(environ, start_response)
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.handle_exception(e)
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
rv = self.dispatch_request()
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/home/configcar_it/Documents/k8s/ec2_mongodb/ec2_mongodb_validator.py", line 119, in update_method
store = Store_collection.objects.get(id=id).update(**body)
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/mongoengine/document.py", line 610, in update
return self._qs.filter(**self._object_key).update_one(**kwargs)
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/mongoengine/queryset/base.py", line 631, in update_one
return self.update(
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/mongoengine/queryset/base.py", line 555, in update
update = transform.update(queryset._document, **update)
File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/mongoengine/queryset/transform.py", line 301, in update
field = cleaned_fields[-1]
IndexError: list index out of range
The remaining Post, Delete, Get methods are working.
I am giving the input through the postman.
Delete method
#app.route('/stores/<id>', methods=['DELETE'])
def delete_doc(id):
stores = Store_collection.objects.get(id=id).delete()
return 'successfully deleted.', 200
After browsing through the internet, I found out that I specified the field name as "type" in my MongoDB database. After understanding this, I changed "type" --> "types". Now it's working properly.
I understood this by reading the following GitHub issue --> https://github.com/MongoEngine/mongoengine/issues/1194.
Also, the same issue is similar to the word "size". Hope this might be helpful for someone.
I'm trying to test my models using peewee's test_database which is supposed to use the database passed when executing the SQL in the context block. However running the test, I noticed that the production database is always used, which should not be the case.
Here's the exception I get:
======================================================================
ERROR: test_Admin (__main__.DatabaseTestSuite)
----------------------------------------------------------------------
Traceback (most recent call last):
File "db/db_test.py", line 14, in test_Admin
with test_database(test_db, (Admin), create_tables=True):
File "/usr/local/lib/python2.7/dist-packages/playhouse/test_utils.py", line 21, in __enter__
for m in self.models:
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4723, in __iter__
return iter(self.select())
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3149, in __iter__
return iter(self.execute())
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3142, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2826, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3683, in execute_sql
self.commit()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3507, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3676, in execute_sql
cursor.execute(sql, params or ())
File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 166, in execute
result = self._query(query)
File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 835, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1019, in _read_query_result
result.read()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1302, in read
first_packet = self.connection._read_packet()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 981, in _read_packet
packet.check_error()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
ProgrammingError: (1146, u"Table 'db.admin' doesn't exist")
----------------------------------------------------------------------
Here's the test code:
from db import *
import unittest
from playhouse.test_utils import test_database
test_db = MySQLDatabase('testdb',
user='testuser',
password='testpass')
class DatabaseTestSuite(unittest.TestCase):
def test_Admin(self):
with test_database(test_db, (Admin), create_tables=True):
Admin.create(username="testuser",
email="testuser#email.com")
result = Admin.select().where(Admin.user == "testuser")
unittest.assertIsNotNone(result)
if __name__ == '__main__':
unittest.main()
I've opened an issue on the github page, but received no help so far. You can find the issue here. It should provide extra details if needed. Any help would be appreciated, thanks.
The model tuple has a single item and thus requires a trailing comma. Changing this
with test_database(test_db, (Admin), create_tables=True):
to this
with test_database(test_db, (Admin,), create_tables=True):
resolved it.
This seems to be a common problem when I search around, but I can't seem to find a viable resolution. The error is not very helpful as far as I can tell as it doesn't really tell you why the saved session is gone.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/eventlet/wsgi.py", line 481, in handle_one_response
result = self.application(self.environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 37, in __call__
start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/middleware.py", line 47, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 303, in handle_request
return self.eio.handle_request(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/server.py", line 226, in handle_request
environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 79, in handle_get_request
start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 118, in _upgrade_websocket
return ws(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/async_eventlet.py", line 13, in __call__
return super(WebSocketWSGI, self).__call__(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/eventlet/websocket.py", line 127, in __call__
self.handler(ws)
File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 180, in _websocket_handler
self.receive(pkt)
File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 48, in receive
self.server._trigger_event('message', self.sid, pkt.data)
File "/usr/local/lib/python2.7/dist-packages/engineio/server.py", line 330, in _trigger_event
return self.handlers[event](*args)
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 429, in _handle_eio_message
self._handle_event(sid, pkt.namespace, pkt.id, pkt.data)
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 371, in _handle_event
r = self._trigger_event(data[0], namespace, sid, *data[1:])
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 397, in _trigger_event
return self.handlers[namespace][event](*args)
File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 199, in _handler
self.server.environ[sid]['saved_session'] = {}
KeyError: 'baee47721e474a1a9885b41ee0ce1847'
First of all, upgrade the following packages: flask-socketio, python-socketio and python-engineio.
I think that will address your issues. This problem occurred with older versions of Flask-SocketIO. The cause that I identified for this condition was that a handler function (these functions you decorate with socketio.on() decorator) ran for a very long time without properly releasing the CPU. If the function ran for longer than 60 seconds without releasing the CPU, then the system mistakenly considered that the client was gone and disconnected the session, causing a KeyError when that session was accessed later.
The error is addressed in the latest release. But also please make sure you release the CPU so that other tasks that run in the background get a chance to do what they need to do.
I'm trying to do some importing to a DB in App Store 1.9.26, in python 2.7.9, and to do so,I would like to get some logging so I can inspect some variables and have a look on whjt is happening
import logging
[...]
updateDueDate = '2016.3.15'
fmt ='%Y.%m.%d'
fechalinea = datetime.datetime.strptime(updateDueDate,fmt)
fecha_aviso = avisoDB.modificacion.due_date.strftime(fmt)
logging.error = ('Date Call= %s, Date DB= %s' %(fecha_aviso, fechalinea))
Which should be pretty straightforward, but its not working. I think I mess up my python instalation or something that has nothing to do with my code, since the output I get from the devserver is:
TypeError("'str' object is not callable",)
TypeError("'str' object is not callable",)
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 1302, in communicate
req.respond()
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 831, in respond
self.server.gateway(self).respond()
INFO 2015-11-22 16:44:48,554 module.py:809] default: "POST /admin/filemanager HTTP/1.1" 500 -
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 2115, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 272, in __call__
return app(environ, start_response)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 314, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 154, in __call__
response = self.handle_normal_request(environ)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 184, in handle_normal_request
self._PYTHON_LIB_DIR)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/runtime.py", line 152, in HandleRequest
error)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 329, in HandleRequest
return WsgiRequest(environ, handler_name, url, post_data, error).Handle()
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 279, in Handle
logging.exception('')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1609, in exception
error(msg, *args, **kwargs)
TypeError: 'str' object is not callable
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 1302, in communicate
req.respond()
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 831, in respond
self.server.gateway(self).respond()
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 2115, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 272, in __call__
return app(environ, start_response)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 314, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 154, in __call__
response = self.handle_normal_request(environ)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 184, in handle_normal_request
self._PYTHON_LIB_DIR)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/runtime.py", line 152, in HandleRequest
error)
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 329, in HandleRequest
return WsgiRequest(environ, handler_name, url, post_data, error).Handle()
File "/Applications/GoogleAppEngineLauncher 2.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 279, in Handle
logging.exception('')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1609, in exception
error(msg, *args, **kwargs)
TypeError: 'str' object is not callable
INFO 2015-11-22 16:44:48,647 module.py:809] default: "GET /favicon.ico HTTP/1.1" 200 15086
Tried to upgrade python and GAE launcher, google for this problem, but with all the different options I get the same errors, and I'm pretty sure it has nothing to do with my code, but... any one has any idea on what is happening?
Thanks
logging.error = assigns the right-hand-side (in your case, a string) to attribute error of module logging, replacing its previous value (which was a function).
When any Python code (yours or in the SDK) later calls logging.error (which you've set to a string), of course it will produce TypeError("'str' object is not callable",)!
I think I mess up my python instalation
Yes you did, by assigning a string to logging.error.
or something that has nothing to do with my code
It has everything to do with your code -- it's your code that does the mistaken assigning!
I'm having strange error with installing fixture from dumped data. I am using psycopg2, and django1.1.1
silver:probsbox oleg$ python manage.py loaddata /Users/oleg/probs.json
Installing json fixture '/Users/oleg/probs' from '/Users/oleg/probs'.
Problem installing fixture '/Users/oleg/probs.json': Traceback (most recent call last):
File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 153, in handle
obj.save()
File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 163, in save
models.Model.save_base(self.object, raw=True)
File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 495, in save_base
result = manager._insert(values, return_id=update_pk)
File "/opt/local/lib/python2.5/site-packages/django/db/models/manager.py", line 177, in _insert
return insert_query(self.model, values, **kwargs)
File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 1087, in insert_query
return query.execute_sql(return_id)
File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/subqueries.py", line 320, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 2369, in execute_sql
cursor.execute(sql, params)
File "/opt/local/lib/python2.5/site-packages/django/db/backends/util.py", line 19, in execute
return self.cursor.execute(sql, params)
ProgrammingError: can't adapt
First I've checked similar issues on internet. This one seemed to be very related: http://code.djangoproject.com/ticket/5996, as my data has many non ASCII symbols
But actually I've checked my django installation and it's ok there
Could you advice what is wrong
====
Continued investigation after added print statement as suggested by the first answer. Log looks this way:
silver:probsbox oleg$ python manage.py loaddata /Users/oleg/probs.json
Installing json fixture '/Users/oleg/probs' from '/Users/oleg/probs'.
<DeserializedObject: Novice>
<DeserializedObject: Junior>
<DeserializedObject: Chess enthusiast>
<DeserializedObject: Experienced player >
<DeserializedObject: Smart player>
Problem installing fixture '/Users/oleg/probs.json': Traceback (most recent call last):
File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 153, in handle
print obj
File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 155, in __repr__
return "<DeserializedObject: %s>" % smart_str(self.object)
File "/opt/local/lib/python2.5/site-packages/django/utils/encoding.py", line 107, in smart_str
return str(s)
File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 335, in __str__
return force_unicode(self).encode('utf-8')
File "/opt/local/lib/python2.5/site-packages/django/utils/encoding.py", line 71, in force_unicode
s = unicode(s)
File "/Users/oleg/Sites/probsbox/registration/models.py", line 58, in __unicode__
return u"%s's profile" %(self.user.username)
File "/opt/local/lib/python2.5/site-packages/django/db/models/fields/related.py", line 257, in __get__
rel_obj = QuerySet(self.field.rel.to).get(**params)
File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 305, in get
% self.model._meta.object_name)
DoesNotExist: User matching query does not exist.
silver:probsbox oleg$
Error from very last comment
<DeserializedObject: qwert2000's profile>
Problem installing fixture '/Users/oleg/probs.json': Traceback (most recent call last):
File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 154, in handle
obj.save()
File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 163, in save
models.Model.save_base(self.object, raw=True)
File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 495, in save_base
result = manager._insert(values, return_id=update_pk)
File "/opt/local/lib/python2.5/site-packages/django/db/models/manager.py", line 177, in _insert
return insert_query(self.model, values, **kwargs)
File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 1087, in insert_query
return query.execute_sql(return_id)
File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/subqueries.py", line 320, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 2369, in execute_sql
cursor.execute(sql, params)
File "/opt/local/lib/python2.5/site-packages/django/db/backends/util.py", line 19, in execute
return self.cursor.execute(sql, params)
ProgrammingError: can't adapt
The can't adapt error is raised by psycopg2 when it receives an data type that it doesn't know how to translate into a value for a SQL statement. For example, if you accidentally pass a list, say, for a value that is supposed to be an integer, psycopg2 will raise this can't adapt error.
The faq.txt document that ships with the source distribution of psycopg2 explains it this way:
Why does !cursor.execute() raise the exception can't adapt?
Psycopg converts Python objects in a SQL string representation by looking
at the object class. The exception is raised when you are trying to pass
as query parameter an object for which there is no adapter registered for
its class. See :ref:adapting-new-types for informations.
Probably your best first-pass at finding the offending value is to run loaddata in fully verbose mode: python manage.py loaddata --verbosity=2 /Users/oleg/probs.json
Well, I was hoping loaddata verbosity would work and I wouldn't have to confess that I've never found an elegant way of debugging adaptation errors with django's loaddata. In the past, I've resorted to inserting print statements in django's loaddata function so that I can see the values being deserialized when the error occurs. I've edited django/core/management/loaddata.py. Look of obj.save() in the handle() function. I hope this confession inspires someone to share a better solution :-)
Ok, I ended copying dump from my database, and restoring it locally without python...