Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[solved] anki windows 2.1.44 cannot sync (windows 10 anki sync server) #97

Open
cygstar opened this issue Jul 14, 2021 · 6 comments
Open

Comments

@cygstar
Copy link

cygstar commented Jul 14, 2021

hello, there.

using windows 10 as a anki sync server (python 3.8.5), anki windows v2.1.44, and unchecked legacy timezone handling.

01

setup and run ankisyncd normally

00a

E:\AnkiSyncd>python -m ankisyncd
[2021-07-14 19:15:15,261]:INFO:ankisyncd:ankisyncd [unknown version] (https://github.com/ankicommunity/anki-sync-server.git)
[2021-07-14 19:15:15,352]:INFO:ankisyncd:Loaded config from E:\AnkiSyncd\ankisyncd.conf
[2021-07-14 19:15:15,352]:INFO:ankisyncd.users:Found auth_db_path in config, using SqliteUserManager for auth
[2021-07-14 19:15:15,353]:INFO:ankisyncd.sessions:Found session_db_path in config, using SqliteSessionManager for auth
[2021-07-14 19:15:15,357]:INFO:ankisyncd:Serving HTTP on 192.168.1.138 port 27701...

but cannot sync at windows desktop

00
02

selected [upload] then went wrong, at the same time, synced anything to server

03
04

E:\AnkiSyncd>python -m ankisyncd
[2021-07-14 17:58:13,821]:INFO:ankisyncd:ankisyncd [unknown version] (https://github.com/ankicommunity/anki-sync-server.git)
[2021-07-14 17:58:13,911]:INFO:ankisyncd:Loaded config from E:\AnkiSyncd\ankisyncd.conf
[2021-07-14 17:58:13,912]:INFO:ankisyncd.users:Found auth_db_path in config, using SqliteUserManager for auth
[2021-07-14 17:58:13,913]:INFO:ankisyncd.sessions:Found session_db_path in config, using SqliteSessionManager for auth
[2021-07-14 17:58:13,916]:INFO:ankisyncd:Serving HTTP on 192.168.1.138 port 27701...
[2021-07-14 17:58:52,128]:INFO:ankisyncd.users:Authentication succeeded for user [email protected]
[2021-07-14 17:58:52,285]:INFO:ankisyncd.http:192.168.1.138 "POST /sync/hostKey HTTP/1.1" 200 43
[2021-07-14 17:58:52,461]:INFO:ankisyncd.CollectionThread[[email protected]]:Starting...
[2021-07-14 17:58:52,461]:INFO:ankisyncd.CollectionThread[[email protected]]:Running meta(*[], **{'v': 10, 'cv': 'anki,2.1.44 (b2b3275f),win:10'})
[2021-07-14 17:58:53,028]:INFO:ankisyncd.http:192.168.1.138 "POST /sync/meta HTTP/1.1" 200 135
[2021-07-14 17:58:53,030]:INFO:ankisyncd.CollectionThread[[email protected]]:Running begin(*[], **{'skey': '2e8d0158'})
[2021-07-14 17:58:53,031]:INFO:ankisyncd.http:192.168.1.138 "GET /msync/begin?k=208a60cab926e3a39073d873b7311662&v=anki%2C2.1.44+%28b2b3275f%29%2Cwin%3A10 HTTP/1.1" 200 49
[2021-07-14 17:58:53,047]:INFO:ankisyncd.CollectionThread[[email protected]]:Running uploadChanges(*[], **{'data': b'PK\x03\x04\x14\x00\x00\x00\x00\x00Z\x8f\xeeR\x19\xd5\x129\xeas\x00\x00\xeas\x00\x00\x01\x00\x00\x000\xff\xfbP\xc4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Info\x00\x00\x00\x0f\x00\x00\x00\x8d\x00\x00s\xea\x00\x03\x05\t\n\x0e\x10\x12\x15\x17\x1b\x1d...'})
[2021-07-14 17:58:53,219]:INFO:ankisyncd.http:192.168.1.138 "POST /msync/uploadChanges HTTP/1.1" 200 29
[2021-07-14 17:58:53,238]:INFO:ankisyncd.CollectionThread[[email protected]]:Running uploadChanges(*[], **{'data': b'PK\x03\x04\x14\x00\x00\x00\x00\x00Z\x8f\xeeRtg{>H\xea\x00\x00H\xea\x00\x00\x01\x00\x00\x000\xff\xfbP\xc4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Info\x00\x00\x00\x0f\x00\x00\x01\x1e\x00\x00\xeaH\x00\x02\x05\x08\n\r\x10\x12\x14\x17\x19\x1c...'})
[2021-07-14 17:58:53,394]:INFO:ankisyncd.http:192.168.1.138 "POST /msync/uploadChanges HTTP/1.1" 200 29
[2021-07-14 17:58:53,405]:INFO:ankisyncd.CollectionThread[[email protected]]:Running uploadChanges(*[], **{'data': b'PK\x03\x04\x14\x00\x00\x00\x00\x00Z\x8f\xeeR\x1a-&\x1d\xf9\x80\x00\x00\xf9\x80\x00\x00\x01\x00\x00\x000\xff\xfbP\xc4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Info\x00\x00\x00\x0f\x00\x00\x00\x9d\x00\x00\x80\xf9\x00\x03\x06\x08\x0b\r\x10\x11\x15\x18\x1a\x1d...'})
[2021-07-14 17:58:53,551]:INFO:ankisyncd.http:192.168.1.138 "POST /msync/uploadChanges HTTP/1.1" 200 28
[2021-07-14 17:58:53,556]:INFO:ankisyncd.CollectionThread[[email protected]]:Running mediaSanity(*[], **{'local': 55})
[2021-07-14 17:58:53,556]:INFO:ankisyncd.http:192.168.1.138 "POST /msync/mediaSanity HTTP/1.1" 200 25
[2021-07-14 17:59:23,588]:INFO:ankisyncd.http:192.168.1.138 "POST /sync/upload HTTP/1.1" 403 157

if selected [download], lost anything, selected [update], problems are the same

10
13
13a

if selected [later], [legacy timezone handling] disappeared, also ankisyncd showed some messages

14
15

E:\AnkiSyncd>python -m ankisyncd
[2021-07-14 18:37:27,774]:INFO:ankisyncd:ankisyncd [unknown version] (https://github.com/ankicommunity/anki-sync-server.git)
[2021-07-14 18:37:27,864]:INFO:ankisyncd:Loaded config from E:\AnkiSyncd\ankisyncd.conf
[2021-07-14 18:37:27,865]:INFO:ankisyncd.users:Found auth_db_path in config, using SqliteUserManager for auth
[2021-07-14 18:37:27,866]:INFO:ankisyncd.sessions:Found session_db_path in config, using SqliteSessionManager for auth
[2021-07-14 18:37:27,870]:INFO:ankisyncd:Serving HTTP on 192.168.1.138 port 27701...
[2021-07-14 18:54:05,497]:INFO:ankisyncd.CollectionThread[[email protected]]:Starting...
[2021-07-14 18:54:05,497]:INFO:ankisyncd.CollectionThread[[email protected]]:Running begin(*[], **{'skey': 'f2a3a12c'})
[2021-07-14 18:54:05,504]:INFO:ankisyncd.http:192.168.1.138 "GET /msync/begin?k=9c536267dd7b461a8757547ff465a435&v=anki%2C2.1.44+%28b2b3275f%29%2Cwin%3A10 HTTP/1.1" 200 50
[2021-07-14 18:54:05,895]:INFO:ankisyncd.CollectionThread[[email protected]]:Running meta(*[], **{'v': 10, 'cv': 'anki,2.1.44 (b2b3275f),win:10'})
[2021-07-14 18:54:05,900]:INFO:ankisyncd.http:192.168.1.138 "POST /sync/meta HTTP/1.1" 200 136
[2021-07-14 18:54:05,910]:INFO:ankisyncd.CollectionThread[[email protected]]:Running start(*[], **{'minUsn': 0, 'lnewer': True, 'graves': None})
[2021-07-14 18:54:05,911]:ERROR:ankisyncd.CollectionThread[[email protected]]:Unable to start(*[], **{'minUsn': 0, 'lnewer': True, 'graves': None}): 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "E:\AnkiSyncd\ankisyncd\thread.py", line 98, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "E:\AnkiSyncd\ankisyncd\collection.py", line 45, in execute
    ret = func(*args, **kw)
  File "E:\AnkiSyncd\ankisyncd\sync_app.py", line 579, in run_func
    res = handler_method(**keyword_args)
  File "E:\AnkiSyncd\ankisyncd\sync_app.py", line 124, in start
    self.remove(graves)
  File "E:\AnkiSyncd\ankisyncd\sync.py", line 221, in remove
    self.col.remove_cards_and_orphaned_notes(graves['cards'])
TypeError: 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\wsgiref\handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Program Files\Python38\lib\site-packages\webob\dec.py", line 129, in __call__
    resp = self.call_func(req, *args, **kw)
  File "C:\Program Files\Python38\lib\site-packages\webob\dec.py", line 193, in call_func
    return self.func(req, *args, **kwargs)
  File "E:\AnkiSyncd\ankisyncd\sync_app.py", line 523, in __call__
    result = self._execute_handler_method_in_thread(url, data, session)
  File "E:\AnkiSyncd\ankisyncd\sync_app.py", line 588, in _execute_handler_method_in_thread
    result = thread.execute(run_func, kw=keyword_args)
  File "E:\AnkiSyncd\ankisyncd\thread.py", line 79, in execute
    raise ret
  File "E:\AnkiSyncd\ankisyncd\thread.py", line 98, in _run
    ret = self.wrapper.execute(func, args, kw, return_queue)
  File "E:\AnkiSyncd\ankisyncd\collection.py", line 45, in execute
    ret = func(*args, **kw)
  File "E:\AnkiSyncd\ankisyncd\sync_app.py", line 579, in run_func
    res = handler_method(**keyword_args)
  File "E:\AnkiSyncd\ankisyncd\sync_app.py", line 124, in start
    self.remove(graves)
  File "E:\AnkiSyncd\ankisyncd\sync.py", line 221, in remove
    self.col.remove_cards_and_orphaned_notes(graves['cards'])
TypeError: 'NoneType' object is not subscriptable
[2021-07-14 18:54:05,929]:INFO:ankisyncd.http:192.168.1.138 "POST /sync/start HTTP/1.1" 500 59
[2021-07-14 18:54:05,932]:INFO:ankisyncd.http:192.168.1.138 "POST /sync/abort HTTP/1.1" 404 154
[2021-07-14 18:55:43,390]:INFO:ankisyncd.ThreadingCollectionManager:Monitor is closing collection on inactive CollectionThread[[email protected]]
[2021-07-14 18:55:43,391]:INFO:ankisyncd.CollectionThread[[email protected]]:Running _close(*[], **{})

those are all info,
best regards.

@dobefore
Copy link
Contributor

Have you configured nginx?
before running server,apply fix #83

@cygstar
Copy link
Author

cygstar commented Jul 16, 2021

Have you configured nginx?

oops, jumped over this step, will try it again.
thank you so much for the help, sir.

@cygstar
Copy link
Author

cygstar commented Jul 17, 2021

many thanks again.

have set up nginx windows 1.20.1, and start the service as normal.
nginx.conf

## anki_sync_server;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       27701;
        server_name  192.168.1.138;

		location / {
			proxy_http_version 1.0;
			proxy_pass         http://192.168.1.138:27702;
		}

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
E:\AnkiSyncd>tasklist /fi "imagename eq nginx.exe"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
nginx.exe                     7088 Console                    1      7,632 K
nginx.exe                     8264 Console                    1      8,212 K

fixed #83 at sync_app.py, started the sync server

E:\AnkiSyncd>python -m ankisyncd
[2021-07-16 18:08:50,585]:INFO:ankisyncd:ankisyncd [unknown version] (https://github.com/ankicommunity/anki-sync-server.git)
[2021-07-16 18:08:50,679]:INFO:ankisyncd:Loaded config from E:\AnkiSyncd\ankisyncd.conf
[2021-07-16 18:08:50,679]:INFO:ankisyncd.users:Found auth_db_path in config, using SqliteUserManager for auth
[2021-07-16 18:08:50,679]:INFO:ankisyncd.sessions:Found session_db_path in config, using SqliteSessionManager for auth
[2021-07-16 18:08:50,679]:INFO:ankisyncd:Serving HTTP on 192.168.1.138 port 27702...

if using module anki 2.1.40, works abnormally
then, upgraded to anki 2.1.44
great, it can sync now, but still has one major issue.

cannot sync media files

even cannot create a media folder [collection.media] at server
(instead of no nginx, it can sync anything to the server)

Fri Jul 16 18:09:27 2021: Media sync starting...
Fri Jul 16 18:09:27 2021: A network error occurred.

Error details: HTTP status client error (413 Payload Too Large) for url ()

05
10

ankisyncd.conf

[sync_app]
# change to 127.0.0.1 if you don't want the server to be accessible from the internet
host = 192.168.1.138
port = 27702
data_root = ./collections
base_url = /sync/
base_media_url = /msync/
auth_db_path = ./auth.db
# optional, for session persistence between restarts
session_db_path = ./session.db

ankiSyncd.py

import os

addr = 'http://192.168.1.138:27701/' ## put your server address here
os.environ['SYNC_ENDPOINT'] = addr + 'sync/'
os.environ['SYNC_ENDPOINT_MEDIA'] = addr + 'msync/'

also tried nginx 1.21.1, the problem is still the same.

finally, it can sync on anki v2.1.44 windows desktop. good news.
real appreciate that you guys all hard work. thank you.

@cygstar cygstar changed the title anki windows desktop 2.1.44 cannot sync (windows 10 anki sync server) [solved] anki windows desktop 2.1.44 cannot sync (windows 10 anki sync server) Jul 17, 2021
@cygstar
Copy link
Author

cygstar commented Jul 17, 2021

now can sync all media files, without any issues.

put following line

client_max_body_size 0;

into http {} in nginx.conf to disable the body size check
then reload nginx and restart sync server

many thanks to dobefore and VikashKothary
best regards!

@cygstar
Copy link
Author

cygstar commented Jul 17, 2021

installing anki sync server for windows 10, and sync at anki 2.1.44 windows version

  1. download and install python 3.8.x windows edition
  2. download anki-sync-server, unzip .\src into a local disk folder [for example: E:\AnkiSyncd]
  3. open cmd as administrator at local disk folder
E:\AnkiSyncd>
  1. Install the dependencies
pip install -r requirements.txt
  1. upgrade anki module to 2.1.44
pip install anki==2.1.44 -U
  1. modify ankisyncd.conf
    (must change the host ip address xxx.xxx.xxx.xxx to suit yours, for example your server/pc ip adress: 192.168.1.138)
[sync_app]
# change to 127.0.0.1 if you don't want the server to be accessible from the internet
host = xxx.xxx.xxx.xxx
port = 27702
data_root = ./collections
base_url = /sync/
base_media_url = /msync/
auth_db_path = ./auth.db
# optional, for session persistence between restarts
session_db_path = ./session.db
  1. create user and password
    (fully support for ankidroid, if using like email address, for example of username: [email protected])
python ankisyncctl.py adduser <username>
  1. download nginx-1.21.1, unzip all to local disk folder and setup nginx
    modify nginx.conf at .\conf and change proxy_pass ip address xxx.xxx.xxx.xxx to suit yours.
## anki_sync_server;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

	# set client body size to 0, disable the body size check
	client_max_body_size 0;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       27701;
        server_name  192.168.1.138;

		location / {
			proxy_http_version 1.0;
			proxy_pass         http://xxx.xxx.xxx.xxx:27702;
		}

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
  1. start nginx service
start nginx

or reload nginx if nginx.conf has changed

nginx -s reload

check nginx service if started

tasklist /fi "imagename eq nginx.exe"

nginx is started, if showing those messages

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
nginx.exe                    11416 Console                    1      7,688 K
nginx.exe                     8612 Console                    1      8,040 K
  1. fix fix:'NoneType' object is not subscriptable_41_ #83 in sync_app.py at .\ankisyncd
    link: 7d8c22c
  2. start the anki sync server
python -m ankisyncd
  1. create an anki 2.1 type addon at anki addon folder .\addons21
    (must change addr xxx.xxx.xxx.xxx to your anki sync server ip address)

Create a new directory in the add-ons folder (name it something like ankisyncd), create a file named __init__.py containing the code below and put it in the ankisyncd directory.

python file must save as code page utf-8

# -*- coding: utf-8 -*-
#----------------------------------------------------------------------

import os

addr = 'http://xxx.xxx.xxx.xxx:27701/' ## put your server address here
os.environ['SYNC_ENDPOINT'] = addr + 'sync/'
os.environ['SYNC_ENDPOINT_MEDIA'] = addr + 'msync/'
  1. run and setup sync user/password at anki 2.1.44 windows, then anything will be syncd
  2. setup ankidroid 2.15.6
    settings --> advanced --> custom sync server
    check [custom sync server]

sync url: (xxx.xxx.xxx.xxx must be your anki sync server ip address)

http://xxx.xxx.xxx.xxx:27701/

media sync url:

http://xxx.xxx.xxx.xxx:27701/msync/

settings --> ankidroid --> ankiweb account
enter username and password, and log in
15. quit nginx

nginx -s quit

@cygstar cygstar changed the title [solved] anki windows desktop 2.1.44 cannot sync (windows 10 anki sync server) [solved] anki windows 2.1.44 cannot sync (windows 10 anki sync server) Jul 17, 2021
@VikashKothary
Copy link
Member

Thanks for documenting the solution for your problem.

If you think it'll help others, do you think you'll be able to raise a PR to include in our documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants