dsnopek / anki-sync-server

A personal Anki sync server (so you can sync against your own server rather than AnkiWeb)
GNU Affero General Public License v3.0
744 stars 95 forks source link

Unicode: need string or buffer, bool found #29

Closed Akendo closed 8 years ago

Akendo commented 8 years ago

There is a bug in the sync process for upload and download. This seems to related when there is a mismatch in the decks.

The Anki Desktop client is telling me to a) Upload my Deck to the Server or B) Download it, to solve the issue. Both requests are causing a expection on the client side.

Syncing failed:
Traceback (most recent call last):
  File "/usr/share/anki/aqt/sync.py", line 324, in run
    self._sync()
  File "/usr/share/anki/aqt/sync.py", line 372, in _sync
    return self._fullSync()
  File "/usr/share/anki/aqt/sync.py", line 409, in _fullSync
    self._syncMedia()
  File "/usr/share/anki/aqt/sync.py", line 416, in _syncMedia
    ret = self.client.sync()
  File "/usr/share/anki/anki/sync.py", line 736, in sync
    ret = self.server.begin()
  File "/usr/share/anki/anki/sync.py", line 870, in begin
    "begin", StringIO(json.dumps(dict())))))
  File "/usr/share/anki/anki/utils.py", line 37, in loads
    s = unicode(s, "utf8")
TypeError: coercing to Unicode: need string or buffer, bool found

There was a quite long message on the server side, while running debug. But as far as I can tell this was the content of the Anki Deck.

I'm going to try to append the output, but only a fraction of it fits into the screen.

Best regards Akendo

Akendo commented 8 years ago

As far as I can see it, the upload is working. The server is returning a True that's send to the client which is expecting a value it can convert into UTF-8. Just a first guess...

Akendo commented 8 years ago

I'm not sure, there are also some type of error message reported.

The Anki Desktop client has some latex Code in there. Since then it's going crazy. As far As I can tell, the AnkiDroid doesn't work with the formual. So it would need to convert them to a png file or something.

But maybe that's is not related to the problem

Akendo commented 8 years ago

The sync process is working somehow. It just has some error message on the client side.

Akendo commented 8 years ago

This is what my client is throwing out now:

Syncing failed:
Traceback (most recent call last):
  File "/usr/share/anki/aqt/sync.py", line 324, in run
    self._sync()
  File "/usr/share/anki/aqt/sync.py", line 385, in _sync
    self._syncMedia()
  File "/usr/share/anki/aqt/sync.py", line 416, in _syncMedia
    ret = self.client.sync()
  File "/usr/share/anki/anki/sync.py", line 736, in sync
    ret = self.server.begin()
  File "/usr/share/anki/anki/sync.py", line 870, in begin
    "begin", StringIO(json.dumps(dict())))))
  File "/usr/share/anki/anki/sync.py", line 598, in req
    self.assertOk(resp)
  File "/usr/share/anki/anki/sync.py", line 545, in assertOk
    raise Exception("Unknown response code: %s" % resp['status'])
Exception: Unknown response code: 404
Akendo commented 8 years ago

Thank you for your reply.

I use the production.ini as the example.ini has been placed. The Anki Desktop Client is configured as in the README pointed out:

[server:main]
use = egg:AnkiServer#server
host = 0.0.0.0
port = 27701

[filter-app:main]
use = egg:Paste#translogger
next = real

[app:real]
use = egg:Paste#urlmap
/ = rest_app
/mediasync = sync_app
/sync = sync_app

[app:rest_app]
use = egg:AnkiServer#rest_app
data_root = ./collections
allowed_hosts = *
logging.config_file = logging.conf

[app:sync_app]
use = egg:AnkiServer#sync_app
data_root = ./collections
base_url = /sync/
base_media_url = /msync/
session_db_path = ./session.db
auth_db_path = ./auth.db

The Client add-on:

import anki.sync

anki.sync.SYNC_BASE = 'http://127.0.0.1:27701/'
anki.sync.SYNC_MEDIA_BASE = 'http://127.0.0.1:27701/msync/'

I start the server(debug or not makes no difference), followed bh the client and the client is getting this type of error message:

Syncing failed:
Traceback (most recent call last):
  File "/usr/share/anki/aqt/sync.py", line 324, in run
    self._sync()
  File "/usr/share/anki/aqt/sync.py", line 385, in _sync
    self._syncMedia()
  File "/usr/share/anki/aqt/sync.py", line 416, in _syncMedia
    ret = self.client.sync()
  File "/usr/share/anki/anki/sync.py", line 736, in sync
    ret = self.server.begin()
  File "/usr/share/anki/anki/sync.py", line 870, in begin
    "begin", StringIO(json.dumps(dict())))))
  File "/usr/share/anki/anki/sync.py", line 598, in req
    self.assertOk(resp)
  File "/usr/share/anki/anki/sync.py", line 545, in assertOk
    raise Exception("Unknown response code: %s" % resp['status'])
Exception: Unknown response code: 404

That's the exact server logs I can find:

2016-01-17 14:46:29,986:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669897836288: Initial worker pool
2016-01-17 14:46:29,986:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669889443584: Initial worker pool
2016-01-17 14:46:29,986:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669881050880: Initial worker pool
2016-01-17 14:46:29,987:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669872658176: Initial worker pool
2016-01-17 14:46:29,987:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669864265472: Initial worker pool
2016-01-17 14:46:29,987:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669517891328: Initial worker pool
2016-01-17 14:46:29,988:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669509498624: Initial worker pool
2016-01-17 14:46:29,988:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669501105920: Initial worker pool
2016-01-17 14:46:29,988:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669492713216: Initial worker pool
2016-01-17 14:46:29,989:paste.httpserver.ThreadPool:DEBUG:Started new worker 139669484320512: Initial worker pool
2016-01-17 14:46:33,324:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:46:33,356:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Starting...
2016-01-17 14:46:33,357:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running meta(*[], **{})
2016-01-17 14:46:33,390:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:46:33,391:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running start(*[], **{})
2016-01-17 14:46:33,419:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:46:33,420:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running applyChanges(*[], **{})
2016-01-17 14:46:33,435:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:46:33,437:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running chunk(*[], **{})
2016-01-17 14:46:33,454:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:46:33,457:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running applyChunk(*[], **{})
2016-01-17 14:46:33,480:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:46:33,481:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running sanityCheck2(*[], **{})
2016-01-17 14:46:33,484:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:46:33,485:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running finish(*[], **{})
2016-01-17 14:46:33,559:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:48:14,997:root:INFO:Monitor is closing collection on inactive CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]
2016-01-17 14:48:14,998:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running _close(*[], **{})
2016-01-17 14:49:37,960:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)
2016-01-17 14:49:37,970:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running meta(*[], **{})
2016-01-17 14:49:37,982:paste.httpserver.ThreadPool:DEBUG:Added task (0 tasks queued)

Hope this can help to reproduce or solve this.

Best regards Akendo

Akendo commented 8 years ago

I found the bug, in my production.ini there is follow line:

..
/mediasync = sync_app
/sync = sync_app
..

I had to change it to

...
/msync = sync_app
...

Now everything is working fine!