GithubHelp home page GithubHelp logo

dsnopek / anki-sync-server Goto Github PK

View Code? Open in Web Editor NEW
743.0 743.0 95.0 231 KB

A personal Anki sync server (so you can sync against your own server rather than AnkiWeb)

License: GNU Affero General Public License v3.0

Python 99.24% Shell 0.76%

anki-sync-server's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anki-sync-server's Issues

Python 3 Support

This app does not seem to work with Python 3. I think it would be a good idea to have at least basic polyglot Python 2/3 support.

I also think running using Python 3 or at least emulating python 3 would make things a bit less thorny when dealing with, for example, unicode filenames.

API description

I'm going to create custom client for anki server. And I found your repo on googling anki web api. Looks like your anki-sync-server reproduce API of anki-web. Can you share documentation for endpoints / format of requests / params / etc. ?

Thx in advance

Problem with anki sync server on ubuntu vagrant

I installed anki sync server on vagrant ubuntu. When I start server with ./ankiserverctl.py debug and curl anki server with curl 'http://localhost:27701'`, I got a responseAnkiServer 2.0.5, which means it is working.

But when I try to reach server from host machine (windows 8), browser's response is ERR_CONNECTION_RESET. I have port forwaring set up, which works ok.

What could be a problem?

Failed install using pip

I have Debain system and installed AnkiServer using pip in virtualenv:

pip install AnkiServer
cp ./examples/example.ini production.ini
./bin/ankiserverctl.py debug

The following error appears:

import anki
ImportError: No module named anki

If I download package from PyPi and install manually (python setup.py install)
everything works fine.

Recent efforts to install fail

If I install anki-sync-server and anki from source, and then I adjust the settings in anki so it tries to sync from my local server, sync does not work. The client and server appear to start communicating but then it errors out.

If I run the server with debug, I get the following error.

INFO:root:CollectionThread[/home/d/src/anki-sync-server/collections/d/collection.anki2]: Running meta(*[], **{})
ERROR:root:CollectionThread[/home/d/src/anki-sync-server/collections/d/collection.anki2]: Unable to meta(*[], **{}): 'MediaManager' object has no attribute 'usn'
Traceback (most recent call last):
  File "/home/d/src/anki-sync-server/AnkiServer/threading.py", line 95, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/home/d/src/anki-sync-server/AnkiServer/collection.py", line 58, in execute
    ret = func(*args, **kw)
  File "/home/d/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 470, in runFunc
    result = func(**data)
  File "/home/d/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 75, in meta
    'musn': self.col.media.usn(),
AttributeError: 'MediaManager' object has no attribute 'usn'
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 37860)
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/paste/httpserver.py", line 1068, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 655, in __init__
    self.handle()
  File "/usr/lib/python2.7/dist-packages/paste/httpserver.py", line 442, in handle
    BaseHTTPRequestHandler.handle(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/lib/python2.7/dist-packages/paste/httpserver.py", line 437, in handle_one_request
    self.wsgi_execute()
  File "/usr/lib/python2.7/dist-packages/paste/httpserver.py", line 287, in wsgi_execute
    self.wsgi_start_response)
  File "/usr/lib/python2.7/dist-packages/paste/translogger.py", line 68, in __call__
    return self.application(environ, replacement_start_response)
  File "/usr/lib/python2.7/dist-packages/paste/urlmap.py", line 206, in __call__
    return app(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/webob/dec.py", line 130, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/usr/lib/python2.7/dist-packages/webob/dec.py", line 195, in call_func
    return self.func(req, *args, **kwargs)
  File "/home/d/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 476, in __call__
    result = thread.execute(runFunc)
  File "/home/d/src/anki-sync-server/AnkiServer/threading.py", line 76, in execute
    raise ret
AttributeError: 'MediaManager' object has no attribute 'usn'
----------------------------------------

In the client, at the same time, I get the generic pop-up error.

Syncing failed:
AnkiWeb encountered an error. Please try again in a few minutes, and if the problem persists, please file a bug report.

I assume that the client is too new of a version relative to the server. But I don't know what to do about that. Is this kind of thing the kind of thing that could be fixed with some screwing around? Is it a gorilla of a problem? Thanks for any thoughts or help!

Tips for using Ankiserver on a local network with different machines

My production.ini files
At server:main, in host, put your host/ip as the same in your local network. If your IP is always changing, you have to open your Router page and assign an IP to your machine so that it always grabs the same IP when you connect your machine to the router.

Look for the line with "allowed_host" and remove it. It will work flawlessly.

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

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

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

[app:rest_app]
use = egg:AnkiServer#rest_app
data_root = ./collections
;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

My "mysyncserver.py" file looks like this:

import anki.sync
import httplib2
anki.sync.SYNC_BASE = 'http://192.168.1.105:27701/'
anki.sync.SYNC_MEDIA_BASE = 'http://192.168.1.105:27701/msync/'
anki.sync.httpCon = lambda: httplib2.Http()

In order to make it work outside network (using internet, 3g, 4g etc), you can use this tutorial:
http://www.htpcguides.com/get-nag-free-dynamic-dns-with-freedns/

Unicode: need string or buffer, bool found

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

Who do you use for remote hosting?

It seems like unless you are just running the server locally you would need a rather specific remote host - one that doesn't timeout large media syncs, lots of storage for said media files. I'm curious how others are hosting their content remotely.

I'm looking into how much amazon would cost, but guessing I would need something additional to the ec2 instance running the server like an external s3 bucket or something like that to store the media...

change dir debug error

When I changed the directory from the original /home/anki/anki to /mnt/hgfs/ankiServer, then the client clicked the sync button and an error occurred.

root@ankiserver:/mnt/hgfs/AnkiServer# ankiserverctl.py debug production.ini
Starting server in PID 11724.
serving on http://192.168.1.105:27701

Exception happened during processing of request from ('192.168.1.175', 10990)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Paste-2.0.3-py2.7.egg/paste/httpserver.py", line 1085, in process_request_in_thread
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 652, in init
self.handle()
File "/usr/local/lib/python2.7/dist-packages/Paste-2.0.3-py2.7.egg/paste/httpserver.py", line 459, in handle
BaseHTTPRequestHandler.handle(self)
File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
self.handle_one_request()
File "/usr/local/lib/python2.7/dist-packages/Paste-2.0.3-py2.7.egg/paste/httpserver.py", line 454, in handle_one_request
self.wsgi_execute()
File "/usr/local/lib/python2.7/dist-packages/Paste-2.0.3-py2.7.egg/paste/httpserver.py", line 304, in wsgi_execute
self.wsgi_start_response)
File "/usr/local/lib/python2.7/dist-packages/Paste-2.0.3-py2.7.egg/paste/translogger.py", line 69, in call
return self.application(environ, replacement_start_response)
File "/usr/local/lib/python2.7/dist-packages/Paste-2.0.3-py2.7.egg/paste/urlmap.py", line 216, in call
return app(environ, start_response)
File "build/bdist.linux-x86_64/egg/webob/dec.py", line 129, in call
resp = self.call_func(req, *args, **kw)
File "build/bdist.linux-x86_64/egg/webob/dec.py", line 193, in call_func
return self.func(req, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/AnkiServer-2.0.6-py2.7.egg/AnkiServer/apps/sync_app.py", line 501, in call
session = self.session_manager.load(hkey, self.create_session)
File "/usr/local/lib/python2.7/dist-packages/AnkiServer-2.0.6-py2.7.egg/AnkiServer/apps/sync_app.py", line 694, in load
session = self.sessions[hkey] = session_factory(res[1], res[2])
File "/usr/local/lib/python2.7/dist-packages/AnkiServer-2.0.6-py2.7.egg/AnkiServer/apps/sync_app.py", line 409, in create_session
self.setup_new_collection)
File "/usr/local/lib/python2.7/dist-packages/AnkiServer-2.0.6-py2.7.egg/AnkiServer/apps/sync_app.py", line 293, in init
os.mkdir(path)

OSError: [Errno 2] No such file or directory: '/home/anki/anki/collections/liujl'


Logs the entire uploaded database at INFO level

I ran the server and sync'd with Anki. I saw this in the logs:

INFO:root:CollectionThread[.../collections/anki/collection.anki2]:
Running operation_upload(*['SQLite format... (the entire contents of my deck, in sqlite3 format)

I happened to be running in an Emacs terminal at the time, which is very slow to print output, and the sync operation timed-out. I set the log level to ERROR, and everything seemed to work OK.

But, I don't ever want the entire contents of my uploaded decks to appear in log output. Can this log line be modified to not include the entire contents, or at least bump to DEBUG level?

See https://github.com/dsnopek/anki-sync-server/blob/2.0.6/AnkiServer/threading.py#L91

Update "pointing anki to the server" in the readme

There seems to be an easier method of pointing Anki to the server, in the source I found:

SYNC_URL = os.environ.get("SYNC_URL") or "https://ankiweb.net/sync/"

So you could set the sync url by just setting the environment variable $SYNC_URL (untested).

OSError: [Errno 13] Permission denied: '/root/.local'

This error happens when some users try to sync media sometimes. I don't know if it's tied to specific data in their collections, but it does usually happen several times in a row - and then doesn't happen again for a while.

Traceback (most recent call last):
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/threading.py", line 95, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/collection.py", line 58, in execute
    ret = func(*args, **kw)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 466, in runFunc
    result = func(**data)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 89, in remove
    rrem = MediaSyncer.remove(self, fnames, minUsn)
  File "/usr/share/anki/anki/sync.py", line 712, in remove
    self.col.media.syncRemove(fnames)
  File "/usr/share/anki/anki/media.py", line 248, in syncRemove
    send2trash.send2trash(f)
  File "/usr/share/anki/thirdparty/send2trash/plat_other.py", line 157, in send2trash
    trash_move(path, dest_trash, topdir)
  File "/usr/share/anki/thirdparty/send2trash/plat_other.py", line 77, in trash_move
    check_create(filespath)
  File "/usr/share/anki/thirdparty/send2trash/plat_other.py", line 63, in check_create
    os.makedirs(dir, 0700)
  File "/opt/anki_server/AnkiServer.env/lib/python2.6/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/opt/anki_server/AnkiServer.env/lib/python2.6/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/opt/anki_server/AnkiServer.env/lib/python2.6/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/opt/anki_server/AnkiServer.env/lib/python2.6/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/root/.local'

I suspect this might have to do with an os.chdir() in the media sync'ing code which is a totally dangerous thing to do in a multithreading application - but I haven't had a chance to test that theory.

Overall, I don't think we need the 'send2trash' functionality on the server, so that can probably be removed all together.

A new release is needed to make the README usable

The README mentions the debug command, but the most recent version in pip does not have that, because it's almost a year old. Of course one can clone from github as need be. Is that the desirable installation method? I'm OK with whichever, and it'd be nice for the documentation to match.

WindowsError: [Error 2] while debug

First, Thanks for building this wonderful project!
I've tried this project's instruction on Win10 64bit with python 2.7 and get some error.
Kindly help to check the solution, thanks.
======Error Message========

Traceback (most recent call last):
File "C:\Python27\Scripts\ankiserverctl.py", line 4, in
import('pkg_resources').run_script('ankiserver==2.0.6', 'ankiserverctl.py')
File "C:\Python27\lib\site-packages\pkg_resources_init_.py", line 743, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "C:\Python27\lib\site-packages\pkg_resources_init_.py", line 1498, in run_script
exec(code, namespace, namespace)
File "c:\python27\lib\site-packages\ankiserver-2.0.6-py2.7.egg\EGG-INFO\scripts\ankiserverctl.py", line 169, in
main()
File "c:\python27\lib\site-packages\ankiserver-2.0.6-py2.7.egg\EGG-INFO\scripts\ankiserverctl.py", line 151, in main
startsrv(sys.argv[2], True)
File "c:\python27\lib\site-packages\ankiserver-2.0.6-py2.7.egg\EGG-INFO\scripts\ankiserverctl.py", line 42, in startsrv
subprocess.call( ["paster", "serve", configpath], shell=False)
File "C:\Python27\lib\subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 390, in init
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2]

Bundled Anki appears to be too old

Hi.
When i run this server with the bundled Anki (i.e. v2.0.11/dae/anki@1a9ef37) and use a new (2.0.18 or 2.0.19) desktop client, the sync process always wants to do a full sync. With the desktop Anki downgraded to the same commit it seems to work fine.

Sync error : database corrupted

Hi, first, thank you for your work.

I manage to get anki-sync-server to run on my personnal server, I use it with 2 devices (1 one computer, and one phone). But each time that I do make a change on a device or on the other I get this error telling me that my decks can't be merged !
anki_screenshot_1

This is a pain, can you do something ?
Thanks again

Problem using nginx

I'm trying to setup anki-sync-server in combination with nginx because I want to use TLS (configured on port 27702). The anki-sync-server itself is working, I can sync when I connect directly to port 27701 over HTTP.
I used the recommended code snippet for nginx from the README page. But I had to change line
proxy_pass http://anki:27701;
to
proxy_pass http://127.0.0.1:27701;
because the orignal line was giving the error message:

nginx: [emerg] host not found in upstream "anki" in /etc/nginx/conf.d/secure.conf:92

When I press the sync button in Anki I get the error message:

Syncing failed:
AnkiWeb is under maintenance. Please try again in a few minutes.

In the logfile of nginx it says:

2017/05/03 00:24:18 [error] 2128#2128: *1783 connect() failed (111: Connection refused) while connecting to upstream, client: 1.1.1.1, server: mydomain.net, request: "POST /sync/hostKey HTTP/1.1", upstream: "http://127.0.0.1:27701/sync/hostKey", host: "mydomain.net:27702"

(I replaced my IP adress with 1.1.1.1 and the domain name of my server with mydomain.net in the error message for privacy reasons)

Anki Droid request deleted files and fails with downloadFiles()

@Akendo I saw the issue #45 you raised for media sync. also noticed @cdpm provided a fix #46 for it.
I got same problem as you mentioned in comment, deleted files from anki PC, then trying to sync by using ankidroid, the console says file missing.

seems it is still trying to download those media files which was already deleted.

any ideas? thanks.

INFO:root:CollectionThread[E:\ankiserver\collections\ninja33\collection.anki2]:Running downloadFiles(*[], **{})
ERROR:root:CollectionThread[E:\ankiserver\collections\ninja33\collection.anki2]: Unable to downloadFiles(*[], **{}): [Error 2] : u'E:\\ankiserver\\collections\\ninja33\\collection.media\\oxford-001700da-22a4a425-6ef26aaa-d6bad639-8f7b2b58.mp3'
Traceback (most recent call last):
  File "e:\python27\lib\site-packages\ankiserver-2.0.6-py2.7.egg\AnkiServer\threading.py", line 95, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "e:\python27\lib\site-packages\ankiserver-2.0.6-py2.7.egg\AnkiServer\collection.py", line 58, in execute
    ret = func(*args, **kw)
  File "e:\python27\lib\site-packages\ankiserver-2.0.6-py2.7.egg\AnkiServer\apps\sync_app.py", line 655, in run_func
    res = handler_method(**keyword_args)
  File "e:\python27\lib\site-packages\ankiserver-2.0.6-py2.7.egg\AnkiServer\apps\sync_app.py", line 248, in downloadFiles
    z.write(os.path.join(self.col.media.dir(), fname), str(cnt))
  File "e:\python27\lib\zipfile.py", line 1123, in write
    st = os.stat(filename)
WindowsError: [Error 2] : u'E:\\ankiserver\\collections\\ninja33\\collection.media\\oxford-001700da-22a4a425-6ef26aaa-d6bad639-8f7b2b58.mp3'

ERROR: unable to begin(*[], **{})

Hi !

I recently started to use Anki and now I want to synchronize my decks with a hosted server. I manage my services using Docker, so I wrote a quick Dockerfile for your server and you can find the result here. I'm using the latest version of AnkiServer on pip: 2.0.6.

Everything seems to work well, I can enter my username and password (I'm connecting with AnkiDroid), but when I try to synchronize, AnkiDroid fails due to "Internal Server Error (500)".

Meanwhile, on the server side, I get the following logs:

INFO:root:CollectionThread[/anki/collections/niels/collection.anki2]: Running meta(*[], **{})
82.251.8.134 - - [17/Sep/2016:22:53:47 +0000] "POST /sync/meta HTTP/1.1" 200 108 "-" "AnkiDroid-2.6.1"
INFO:root:CollectionThread[/anki/collections/niels/collection.anki2]: Running begin(*[], **{})
ERROR:root:CollectionThread[/anki/collections/niels/collection.anki2]: Unable to begin(*[], **{}): begin() takes exactly 2 arguments (1 given)
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/AnkiServer/threading.py", line 95, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/usr/lib/python2.7/site-packages/AnkiServer/collection.py", line 58, in execute
    ret = func(*args, **kw)
  File "/usr/lib/python2.7/site-packages/AnkiServer/apps/sync_app.py", line 651, in run_func
    res = handler_method(**keyword_args)
TypeError: begin() takes exactly 2 arguments (1 given)
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/paste/httpserver.py", line 1085, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 652, in __init__
    self.handle()
  File "/usr/lib/python2.7/site-packages/paste/httpserver.py", line 459, in handle
    BaseHTTPRequestHandler.handle(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/lib/python2.7/site-packages/paste/httpserver.py", line 454, in handle_one_request
    self.wsgi_execute()
  File "/usr/lib/python2.7/site-packages/paste/httpserver.py", line 304, in wsgi_execute
    self.wsgi_start_response)
  File "/usr/lib/python2.7/site-packages/paste/translogger.py", line 69, in __call__
    return self.application(environ, replacement_start_response)
  File "/usr/lib/python2.7/site-packages/paste/urlmap.py", line 216, in __call__
    return app(environ, start_response)
  File "/usr/lib/python2.7/site-packages/webob/dec.py", line 130, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/usr/lib/python2.7/site-packages/webob/dec.py", line 195, in call_func
    return self.func(req, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/AnkiServer/apps/sync_app.py", line 582, in __call__
    result = self._execute_handler_method_in_thread(url, data, session)
  File "/usr/lib/python2.7/site-packages/AnkiServer/apps/sync_app.py", line 660, in _execute_handler_method_in_thread
    result = thread.execute(run_func)
  File "/usr/lib/python2.7/site-packages/AnkiServer/threading.py", line 76, in execute
    raise ret
TypeError: begin() takes exactly 2 arguments (1 given)

Any idea on why this happens ?

Scheduler not work correct by restful api?

Hi,
i'm try make web client 4 anki , but have some problem in scheduler.

i have test collection and deck with reseted scheduler. On start learning, i have this value on scheduler counters
[learning_cards] => 0
[review_cards] => 0
[new_cards] => 20

while i make response, value in new_cards decrease not every time when i make positive response, and after several time (perhaps 15 minuts or less) counters make reset to 0,0,20 again.
Not understand why in can happen?

Synchronization error between ankidroid and AnkiDesktop

I am using Anki desktop Version 2.0.44 on Windows
I am using AnkiDroid (2.9 version mentionned in help)
Sync server is running on ubuntu on raspberry (anki 2.0.32 installed on server + anki-sync-server install procedure , ubuntu version Linux raspberry 4.4.38-v7)

When I do modification on AnkiDroid only, then doing sync, it is ok (files are pushed on server).
When I do modification on Anki Desktop only, then doing sync, it is ok (files are pushed on server).
The problem is when I do modification on Anki Desktop, then sync on Anki Desktop, then try to sync on AnkiDroid. I then get an error message, and I have to overwrite.
And conversly if I do modification on AnkiDroid, then sync on ankidroid, then try to sync on Anki desktop, I have to overwrite.

I am able to synchronize cards between my two devices, but I get error messages, and have to overwrite.
Do you have any idea of why it happens?
Is there any way to troubleshoot that?

Timezone seems ok on server.

Thanks

Installation failure on Debian

I have a box running Debian sid. I make a new directory, install everything as documented, and I can't run the server. Help?

$ mkdir anki
$ virtualenv anki
$ cd anki
$ source bin/activate
(anki)$ git clone https://github.com/dsnopek/anki-sync-server.git
(anki)$ cd anki-sync-server
(anki)$ cp example.ini production.ini
(anki)$ ./ankiserverctl.py debug
Traceback (most recent call last):
  File "./ankiserverctl.py", line 169, in <module>
    main()
  File "./ankiserverctl.py", line 151, in main
    startsrv(sys.argv[2], True)
  File "./ankiserverctl.py", line 42, in startsrv
    subprocess.call( ["paster", "serve", configpath], shell=False)
  File "/usr/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

OK, maybe I should add a user first. That appears to work.

./ankiserverctl.py adduser joe2
Enter password for joe2: 
Password: 

The data and password files and directories look OK, as far as I can see, but if I try running the server, the above error shows up just like before.

./ankiserverctl.py debug
Traceback (most recent call last):
  File "./ankiserverctl.py", line 169, in <module>
    main()
  File "./ankiserverctl.py", line 151, in main
    startsrv(sys.argv[2], True)
  File "./ankiserverctl.py", line 42, in startsrv
    subprocess.call( ["paster", "serve", configpath], shell=False)
  File "/usr/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Help?

SSL support

Hi David,

I would like to run anki-sync-server over SSL, but pointing SYNC_URL to the HTTPS URL is not enough because Anki does SSL certificate validation and only accepts the certificates for AnkiWeb in ankiweb.certs. Are you aware of any workaround?

-ag

Anki 2.0.39 Makefile PREFIX=/usr changed to PREFIX=/usr/local

I noticed with the latest Anki 2.0.39 version, the PREFIX in makefile has changed from:

PREFIX=/usr

to

PREFIX=/usr/local

This causes sudo make install to install Anki in a different directory than for previous versions, which causes a ImportError: No module named anki when you try to start the server. I wish I could point you to where in the repo this change happened but it looks like Damien bumps the version from 2.0.36 to 2.1 alpha without any mention of going to 2.0.39. However, you can take a look for yourself in the 2.0.39 tar.bz2 or on the ankisrs.net changes page.

Here's how to reproduce the error in Ubuntu 16.04.

Install Anki 2.0.39

wget https://apps.ankiweb.net/downloads/current/anki-2.0.39-amd64.tar.bz2
tar jxvf anki-2.0.39-amd64.tar.bz2
cd anki-2.0.39
sudo make install

Install AnkiServer

sudo pip install AnkiServer
cd /usr/local/bin

Configure AnkiServer

sudo touch production.ini
sudo gedit production.ini

Start AnkiServer

sudo ./ankiserverctl.py adduser test
sudo ./ankiserverctl.py debug

Which produces the following error:

Traceback (most recent call last):
  File "/usr/local/bin/paster", line 11, in <module>
    sys.exit(run())
  File "/usr/local/lib/python2.7/dist-packages/paste/script/command.py", line 102, in run
    invoke(command, command_name, options, args[1:])
  File "/usr/local/lib/python2.7/dist-packages/paste/script/command.py", line 141, in invoke
    exit_code = runner.run(args)
  File "/usr/local/lib/python2.7/dist-packages/paste/script/command.py", line 236, in run
    result = self.command()
  File "/usr/local/lib/python2.7/dist-packages/paste/script/serve.py", line 284, in command
    relative_to=base, global_conf=vars)
  File "/usr/local/lib/python2.7/dist-packages/paste/script/serve.py", line 329, in loadapp
    **kw)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
    return context.create()
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 710, in create
    return self.object_type.invoke(self)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 217, in invoke
    next_app = context.next_context.create()
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 710, in create
    return self.object_type.invoke(self)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 144, in invoke
    **context.local_conf)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/util.py", line 55, in fix_call
    val = callable(*args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/paste/urlmap.py", line 31, in urlmap_factory
    app = loader.get_app(app_name, global_conf=global_conf)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 350, in get_app
    name=name, global_conf=global_conf).create()
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 362, in app_context
    APP, name=name, global_conf=global_conf)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 454, in get_context
    section)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 476, in _context_from_use
    object_type, name=use, global_conf=global_conf)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 406, in get_context
    global_conf=global_conf)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 296, in loadcontext
    global_conf=global_conf)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 328, in _loadegg
    return loader.get_context(object_type, name, global_conf)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 620, in get_context
    object_type, name=name)
  File "/usr/local/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 646, in find_egg_entry_point
    possible.append((entry.load(), protocol, entry.name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python2.7/dist-packages/AnkiServer/apps/sync_app.py", line 32, in <module>
    import anki
ImportError: No module named anki

Workarounds:

Fortunately installing via the 2.0.39 deb file works without any problems. Also, going back to 2.0.36 works as well.

I tried simply changing the PREFIX=/usr/local in the makefile back to PREFIX=/usr and doing a sudo make install from there, but that still does not solve the problem.

Error sync after update local app

  • OS: Archlinux
  • About Anki: Version 2.1.0a10
  • Qt 5.8.0 PyQt 5.7.1

After update descktop app fulfilled daily tasks. Pressed 'Sinchronize with AnkiWeb' and got following error.

An error occurred. It may have been caused by a harmless bug, 
or your deck may have a problem. 
To confirm it's not a problem with your deck, please run Tools > Check Database. 
If that doesn't fix the problem, please copy the following
into a bug report:
Caught exception:
  File "/usr/share/anki/aqt/sync.py", line 346, in run
    self.col.close(save=False)
  File "/usr/share/anki/anki/collection.py", line 156, in close
    self.db.execute("pragma journal_mode = delete")
  File "/usr/share/anki/anki/db.py", line 31, in execute
    res = self._db.execute(sql, a)
<class 'sqlite3.OperationalError'>: cannot change out of wal mode from within a transaction

Local base and AnkiWeb were sinchronized. But this message appear every time.
Check Dtabase - OK.

Anki Droid request deleted files and fails with uploadChanges()

I try to sync some collection with AnkiDroid, but there are some critical problems.

During the synchronization of the AnkiDroid (latest stable version 2.6 from F-Droid)
the AnkDroid tries to download old images from the server, that I have remove via the Desktop Client. (running Tools>Check Media)

I create the files that were missing, but after this he's rasing following error message:

ERROR:root:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Unable to uploadChanges(*[], **{}): not enough arguments for format string
Traceback (most recent call last):
  File "/home/akendo/src/anki-sync-server/AnkiServer/threading.py", line 95, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/home/akendo/src/anki-sync-server/AnkiServer/collection.py", line 58, in execute
    ret = func(*args, **kw)
  File "/home/akendo/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 651, in run_func
    res = handler_method(**keyword_args)
  File "/home/akendo/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 113, in uploadChanges
    processed_count = self._adopt_media_changes_from_zip(data)
  File "/home/akendo/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 191, in _adopt_media_changes_from_zip
    self._remove_media_files(media_to_remove)
  File "/home/akendo/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 236, in _remove_media_files
    "%s" % filename, str(err))
TypeError: not enough arguments for format string
----------------------------------------
Exception happened during processing of request from ('172.17.7.25', 44928)
Traceback (most recent call last):
  File "/home/akendo/.virtualenvs/anki-sync-server/lib/python2.7/site-packages/paste/httpserver.py", line 1085, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/usr/lib64/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib64/python2.7/SocketServer.py", line 652, in __init__
    self.handle()
  File "/home/akendo/.virtualenvs/anki-sync-server/lib/python2.7/site-packages/paste/httpserver.py", line 459, in handle
    BaseHTTPRequestHandler.handle(self)
  File "/usr/lib64/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/home/akendo/.virtualenvs/anki-sync-server/lib/python2.7/site-packages/paste/httpserver.py", line 454, in handle_one_request
    self.wsgi_execute()
  File "/home/akendo/.virtualenvs/anki-sync-server/lib/python2.7/site-packages/paste/httpserver.py", line 304, in wsgi_execute
    self.wsgi_start_response)
  File "/home/akendo/.virtualenvs/anki-sync-server/lib/python2.7/site-packages/paste/translogger.py", line 69, in __call__
    return self.application(environ, replacement_start_response)
  File "/home/akendo/.virtualenvs/anki-sync-server/lib/python2.7/site-packages/paste/urlmap.py", line 216, in __call__
    return app(environ, start_response)
  File "/home/akendo/.virtualenvs/anki-sync-server/lib/python2.7/site-packages/webob/dec.py", line 130, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/home/akendo/.virtualenvs/anki-sync-server/lib/python2.7/site-packages/webob/dec.py", line 195, in call_func
    return self.func(req, *args, **kwargs)
  File "/home/akendo/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 634, in __call__
    return self._execute_handler_method_in_thread(url, data, session)
  File "/home/akendo/src/anki-sync-server/AnkiServer/apps/sync_app.py", line 660, in _execute_handler_method_in_thread
    result = thread.execute(run_func)
  File "/home/akendo/src/anki-sync-server/AnkiServer/threading.py", line 76, in execute
    raise ret
TypeError: not enough arguments for format string
----------------------------------------
INFO:root:Monitor is closing collection on inactive CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]
INFO:root:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running _close(*[], **{})

I'm quite not sure who's causing this type of misbehavior. Any suggestion?

Having trouble syncing with AnkiDroid

Hello,

Thanks for working on this!

I've been trying to use anki-sync-server to see if I could sync to a collection on a personal server from my phone:

https://github.com/dsnopek/anki-sync-server

After much wrangling, I have been able to get the server running, so I can sync my Anki Desktop application to it. However, I've been having trouble getting my phone to sync with it using the following entries in the AnkiDroid Custom Sync server:

Sync url https://192.168.1.149:27701/

Media sync url https://192.168.1.149:27701/msync/

This IP address match what I have on my production.ini file and the mysyncserver.py plugin file. But when I try to sync with AnkiDroid on my home wifi, I am immediately getting a connection timeout error message, so I believe I may have missed something in configuring the server. However, the message takes less than a second to appear, so I don't think it's a matter of the connection taking too long, it seems to be denied altogether.

Can you please help me with this?

Thanks!

Trouble installing from source

Hello,

I'm having some trouble while trying to install Anki Server from source. I'll walk you through what I did:

Install all the dependencies we need using easy_install or pip:

$ easy_install webob PasteDeploy PasteScript sqlalchemy simplejson

Or using pip:

$ pip install webob PasteDeploy PasteScript sqlalchemy simplejson

Or you can use your the package manager provided by your OS.

This went okay. I did sudo pip install webob PasteDeploy PasteScript sqlalchemy simplejson instead, if that matters.

Download and install libanki. You can find the latest release of Anki here:

http://code.google.com/p/anki/downloads/list

Look for a *.tgz file with a Summary of "Anki Source". At the time of this writing that is anki-2.0.11.tgz.

Download this file and extract.

Then either:

Run the 'make install', or
Copy the entire directory to /usr/share/anki

This went okay, too. Except I installed version 2.0.39 using sudo make install.

Make the egg info files (so paster can see our app):

$ python setup.py egg_info

This is where I'm having trouble. This is what I did after cloning the anki-sync-server github repo:

test@test-VirtualBox:~/anki-sync-server$ sudo python setup.py egg_info
running egg_info
creating AnkiServer.egg-info
writing requirements to AnkiServer.egg-info/requires.txt
writing AnkiServer.egg-info/PKG-INFO
writing top-level names to AnkiServer.egg-info/top_level.txt
writing dependency_links to AnkiServer.egg-info/dependency_links.txt
writing entry points to AnkiServer.egg-info/entry_points.txt
writing manifest file 'AnkiServer.egg-info/SOURCES.txt'
reading manifest file 'AnkiServer.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*' under directory 'anki-bundled'
warning: no previously-included files matching '*.pyc' found under directory 'anki-bundled'
no previously-included directories found matching 'anki-bundle/.git'
writing manifest file 'AnkiServer.egg-info/SOURCES.txt'

As you can see, I have a few warning messages. The libraries didn't end up in the usual place (/usr/local/lib/python2.7/dist-packages) and I have been unable to launch the server. What am I doing wrong?

Thank you!

Show errors when running "ankiserverctl.py start" (and re-add info to docs about using "paster")

We've recently gotten a number of reports of people trying Anki Server but it not starting and them getting no feedback:

https://groups.google.com/forum/#!topic/anki-sync-server/OaOadyGmzAE

https://groups.google.com/forum/#!topic/anki-sync-server/IXGpxsdWfOs

It looks like ankiserverctl.py is routing all output to /dev/null. It should either (1) send something out to the console (maybe stderr?) or (2) log stdout/stderr somewhere. When running with supervisord, both stdout/stderr get logged by it which I find very useful, personally...

can't connet anki-sync-server

Hi, first, thank you for your work.
I try to get anki-sync-server to run on my linuxmint 17.1.
I do it following these steps
sudo apt-get install python-pip
sudo pip install AnkiServer
cd /usr/local/bin
cp /usr/local/lib/python2.7/dist-packages/AnkiServer-2.0.6-py2.7.egg/examples/example.ini production.ini
./ankiserverctl.py adduser
./ankiserverctl.py debug
./ankiserverctl.py start
it works great.

and then I open port for anki-sync-server

sudo vim /etc/iptables.firewall.rules
*filter

Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0

-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT

Accept all established inbound connections

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

Allow all outbound traffic - you can modify this to only allow certain traffic

-A OUTPUT -j ACCEPT

Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL).

-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

Allow SSH connections

The -dport number should be the same port number you set in sshd_config

-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

Allow ping

-A INPUT -p icmp --icmp-type echo-request -j ACCEPT

Log iptables denied calls

-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7

Drop all other inbound - default deny unless explicitly allowed policy

-A INPUT -j DROP
-A FORWARD -j DROP

Allow anki sever

-A INPUT -p tcp --dport 27701 -j ACCEPT
COMMIT

sudo iptables-restore < /etc/iptables.firewall.rules
sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere 127.0.0.0/8 reject-with icmp-port-unreachable
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT icmp -- anywhere anywhere icmp echo-request
LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix "iptables denied: "
DROP all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:27701

Chain FORWARD (policy ACCEPT)
target prot opt source destination
DROP all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere

But, I can't connet anki-server from my phone

myphone's parameter

http://192.168.2.128:27701/
http://192.168.2.128:27701/msync/

thanks

Got "WindowsError: [Error 183] " while running it on Paython27/Win7

hi team:
I installed this package (2.0.6) by using easy_install, I successfully logon as username "test" in anki windows client, and anki client prompt me to upload/download all deck info for first time sync, I choose upload. then I got some errors in console.

seems something happened after checking log file

in operation_upload
os.rename(temp_db_path, session.get_collection_path())
WindowsError: [Error 183]

WindowsError: [Error 183] in python usually means you just can not rename that file because it already exists.

Update README

According to the following pull request on the Anki-Android repo, the ability to use a custom sync server is now enable for the Android client. Haven't tested it though.

(After confirmed as usable) please update your README accordingly.

Solution for "no module named Anki" on Windows

If you get the error called "no module named Anki" on Windows, simply copy the anki-bundled folder to

C:\Python27\lib\site-packages (put inside this folder)

Your structure must be like this:
C:\Python27\lib\site-packages\anki-bundled

It works flawlessly.

A way to get tags by deck ?

Hi,

in api I don't see how I can get tags from a deck instead of all decks of collections.
Did you plan to implement an "list_tags_by_deck" or something like that ?

Regards,

Issue when syncing media

In debug with media sync sometimes I get this:

192.168.0.24 - - [20/Aug/2017:16:01:39 -0500] "POST /sync/meta HTTP/1.1" 200 115 "-" "Python-httplib2/0.7.7 (gzip)"
Traceback (most recent call last):
  File "/usr/lib/python2.7/logging/__init__.py", line 851, in emit
    msg = self.format(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 724, in format
    return fmt.format(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 467, in format
    s = self._fmt % record.__dict__
MemoryError

I'm on ubuntu bash on windows. I managed to get the server running, but my deck has about 200k media cards. I originally got a memory error, but now the server in debug mode doesn't say anything and the anki client says the string buffer error below, under the condition i don't do a media sync.
I'm getting this ambiguous error and not able to figure out what the bad response actually is, since anki only throws this up:

Syncing failed:
Traceback (most recent call last):
  File "aqt\sync.py", line 324, in run
  File "aqt\sync.py", line 385, in _sync
  File "aqt\sync.py", line 416, in _syncMedia
  File "anki\sync.py", line 739, in sync
  File "anki\sync.py", line 873, in begin
  File "json\__init__.py", line 326, in loads
  File "json\decoder.py", line 366, in decode
TypeError: expected string or buffer

The reason for me doing a custom server is because I hope to get around the 250MB collection limit. Is it possible to only sync with the custom server your base and no media - since there is no restriction on collection media size?

I removed the line from mysyncserver.py to be, but get the same ambiguous error

import anki.sync
anki.sync.SYNC_BASE = 'http://127.0.0.1:27701/'

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

If I disable media sync, things work just fine.

UnicodeDecodeError

I'm not good at English.So I can only briefly describe the situation.
I encountered some errors during the execution of the program like the picture.
default

[Feature Request] - RESTful add/remove/modify users & location change of dbs

I've recently forked this project to dockerize it, which went pretty smoothly. I'd like to send a pull request to merge this in, but before then I think it would be great if there were a RESTful way to add & delete users, and change their passwords.

If this project is still under active development, it would be great if this could be added. Glancing at the code it looks like it would be pretty easy to add, but I'm new to Python. The interface could itself be protected by a username & password that the server gets from the environment, which is easy for Docker users to set at deploy time.

Also, to facilitate docker deployments, it would be most welcome if the various databases could be created in a subdirectory containing nothing else, so that this directory can be mapped to persistent storage on the host.

I'm willing to do all this work myself, but I thought I'd open an issue first to give you the opportunity to do it yourself and avoid any potential blunders by a Python newb like myself.

Syncing inconsistencies

I switched from AnkiWeb to this sync server a few days ago, and I've encountered this problem multiple times since then. Tried Check Database, and full sync multiple times, but it didn't solve my problem.

I couldn't exactly pinpoint what causes this problem, but is seems like doing a bunch of reviews or editing a few cards can trigger this error. After doing some reviews on AnkiDroid and then sync, when I try to sync with desktop anki, I sometimes get "Your collection is in an inconsistent state." error, and forces a full sync. The same can happen if I edit my cards on desktop, and try to sync back to AnkiDroid.

I tried what happens if I leave out AnkiDroid and try to sync between two desktop an ankis. I've rescheduled some cards on computer A, synced A, synced B, looks ok, except the changes are not visible on B. If I force a full sync, changes appear on computer B too.

I use the version from pip in a virtualenv (I had to work-around #40 by moving the anki-bundled folder into lib/python2.7/site-packages...). ankiserverctl.py debug doesn't show any obvious errors or problems.

OperationalError: cannot change out of wal mode from within a transaction

There is a particular user who gets this error any time they sync:

Traceback (most recent call last):
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/threading.py", line 95, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/collection.py", line 58, in execute
    ret = func(*args, **kw)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/threading.py", line 145, in _close
    self.wrapper.close()
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/collection.py", line 105, in close
    self.__col.close()
  File "/usr/share/anki/anki/collection.py", line 140, in close
    self.db.execute("pragma journal_mode = delete")
  File "/usr/share/anki/anki/db.py", line 35, in execute
    res = self._db.execute(sql, a)
OperationalError: cannot change out of wal mode from within a transaction

I don't know what in particular is up with their collection that this happens - I'll attempt to determine that. However, this error occurs when the Anki Server is attempting to close the collection - which means it never gets closed and the server keeps trying over and over again. In fact, the only way to stop it, is to restart the server!

So, even if I don't figure out what's causing this, I need to at least change the close code to make sure it gets closed (even if it's forced!) so that we don't have an infinite loop.

com.ichi2.anki.exception.UnknownHttpResponseException: Internal Server Error

Hello,

I've been experiencing some odd behavior regarding the sync on AnkiDroid. Sometimes when I sync, "Writing changes into database..." will hang at 1459 kB for about 3 minutes, after which I get the error message:

screenshot_20170108-211540

screenshot_20170108-132456

The cards seem to update, but the media doesn't. I tried syncing against an empty folder, but only about 1/3rd of the media downloaded, then I got the error message above. This issue is only happening on my phone. Desktop-to-desktop syncs work fine.

I did a hard reboot of my phone and I was able to redownload all the media files. I then added some media to my desktop collection to see if I could sync it to my Android phone. The syncing screen took a minute, but I was able to successfully sync the media. I'll see if I can reproduce the issue.

How to handle CollectionHandler.answer_card() / .next_card() when scheduler isn't setup?

Here is the stacktrace seen in the wild:

Unable to answer_card(*[<AnkiServer.apps.rest_app.RestHandlerRequest object at 0x179da50>], **{}): 'Scheduler' object has no attribute 'lrnCount'
Traceback (most recent call last):
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/threading.py", line 95, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/collection.py", line 58, in execute
    ret = func(*args, **kw)
  File "/opt/anki_server/src/anki-sync-server/AnkiServer/apps/rest_app.py", line 561, in answer_card
    col.sched.answerCard(card, ease)
  File "/usr/share/anki/anki/sched.py", line 74, in answerCard
    self._answerLrnCard(card, ease)
  File "/usr/share/anki/anki/sched.py", line 549, in _answerLrnCard
    self.lrnCount += card.left // 1000
AttributeError: 'Scheduler' object has no attribute 'lrnCount'

It happens when a review is started (reset_scheduler(), next_card()), the Collection is closed for inactivity, and THEN the user does answer_card(). The Collection is re-opened, but reset_scheduler() isn't run.

The error will only appear when the card is in the "learning" queue, but it's probably a problem in many other cases. For example, .next_card() won't necessarily know the current deck and so who knows what it will return!

Additionally, in the specific case of answer_card(), we're marking as @noReturnValue, so the error never bubbles up to user. They don't even know that their answer wasn't recorded. :-/

Beyond this specific issue, this is a problem of using a stateless protocol (HTTP) to work with an inherently stateful system (Anki). I'm not sure what the full solution is... Maybe passing some sort of session setup information with every call to .next_card() and .answer_card()? That way, if the schedule isn't setup, it can be re-setup?

I'm not yet sure how to handle this...

Can't use it as personal server.

I can run ./ankiserverctl.py debug without errors, but when I try to use it as a customer sync server for my desktop anki, I can't log on. Does it need additional set up to make it work? I'm from china, and the official ankiweb is very slow, so it would be so nice to have a personal anki sync service running on my server. Thanks for you hard work!

python3 or python2 ?

There is a problem after pip install AnkiServer:

  1. Server code need run with python2.
  2. Anki code in anki-bundled fold need run with python3.
    How to resolve this?

README: Google Code link is no longer supported

From the README:

Download and install libanki. You can find the latest release of Anki here:

http://code.google.com/p/anki/downloads/list

Look for a *.tgz file with a Summary of "Anki Source". At the time of this writing that is anki-2.0.11.tgz.

There are no longer any download links at http://code.google.com/p/anki/downloads/list, and based on Google Code's end-of-life status, I doubt they will ever be restored.

I was able to find the Anki source via the following method:

Go to https://apps.ankiweb.net/

In the section "Download Anki" select "Linux/BSD".

In the "Other Options" section, there should be a link reading "Source .tgz". At the time of writing this file is called "anki-2.0.45.tgz".

The README should be updated to provide a working path to download the Anki source.

uploadChanges seems broken

Hi

I did run in on of my decks following check_media feature to clean up all of my unnecessary elements.

Afterwards I did sync to the anki-sync-server.
But the sync nerver finsihed, the client is keeping uploading to the server without any progress.

In the logs files I can see that he's executing all the time the uploadChanges .

at first I can see how some payload is uploaded, but then I can't see any change.
It seems to me like a loop that is not finished or something.

2016-01-23 11:52:51,309:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running uploadChanges(*[], **{})
2016-01-23 11:52:51,321:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running uploadChanges(*[], **{})
2016-01-23 11:52:51,332:paste.httpserver.ThreadPool:INFO:kill_hung_threads status: 10 threads (0 working, 10 idle, 0 starting) ave time N/A, max time 0.00sec, 
killed 0 workers
2016-01-23 11:52:51,333:root:INFO:CollectionThread[/home/akendo/src/anki-sync-server/collections/akendo/collection.anki2]: Running uploadChanges(*[], **{})

Any idea?

httplib2 is not declared as a dependency

When installing in a fresh virtualenv, trying to run ankiserverctl.py gives:

ImportError: No module named httplib2

I believe this is just a matter of adding httplib2 into the dependencies in setup.py. Installing httplib2 with pip fixes the issue.

[Feature Request / Clarification] Headless mode?

I found out about the project and as far as I can tell the server itself doesn't require anything graphical or X-related. However, at least for my Linux distro, anki itself is a dependency, which necessitates all of X. Of course, I was keen to use this on my headless server (for my home LAN), and would very much prefer to not install that whole set of packages.

Is there something I've fundamentally misunderstood / overlooked about how anki-sync-server operates? If not, should I request the maintainers of anki-sync-server that "anki" no longer be a dependency, or at least be "optional"?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.