kuklinistvan / docker-anki-sync-server

Anki Sync Server with Docker - and it works!
GNU General Public License v3.0
133 stars 24 forks source link

OS X issue related to media syncing #6

Closed adamwolf closed 5 years ago

adamwolf commented 5 years ago

Hi folks!

Thanks so much for this awesome software and packaging. Works like a dream on Ankidroid now!

I installed SyncDirector on Anki 2.1 on my mac, and I set up the urls

{ "msyncUrl": "https://anki-sync-server.coldbloomlabs.com/msync/", "syncUrl": "https://anki-sync-server.coldbloomlabs.com/sync/" }

Please note these work fine on Ankidroid.

When I try to log in on Anki for macOS, I get the following error in Anki

Syncing failed: Traceback (most recent call last): File "aqt/sync.py", line 342, in run File "aqt/sync.py", line 367, in _sync File "anki/sync.py", line 581, in hostKey File "json/init.py", line 354, in loads File "json/decoder.py", line 339, in decode File "json/decoder.py", line 357, in raw_decode json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

and the following request in the server logs.

2019-05-02T21:42:12.368269003Z app[web.1]: [2019-05-02 21:42:12,367]:INFO:ankisyncd.http:172.17.0.1 "POST /5sync/hostKey HTTP/1.1" 200 16

I think that 5 is incorrect... where is it coming from?!

Any thoughts?

kuklinistvan commented 5 years ago

This is interesting indeed. I apologize in advance for replying slowly in the further correspondence - I'm having some exams in the next couple weeks - but I'll try to take some time to look at the problem shortly.

Can you give us the exact version of your Anki Desktop instance? Are you using the latest version of the Docker image?

Thank you for reporting and stay tuned!

adamwolf commented 5 years ago

No problem. I understand you are providing a great service and help for free, and of course you have other things going on :)

I am also digging into the Anki source myself, a debugger should show me where this 5 is coming from pretty quickly.

I am running Anki Desktop Version 2.1.12 (eef86bf3) downloaded from teh website, and I ran the Docker image last night like "kuklinistvan/anki-sync-server:latest".

adamwolf commented 5 years ago

Looks like it has to do with the updates in Anki for splitting across multiple sync servers. Ankidroid doesn't have that yet, which is why it works. I think we can fix this by updating the addon.

tsudoko commented 5 years ago

Here's how it was fixed in the addons supplied with tsudoko/anki-sync-server, along with the description of the problem and related issues: https://github.com/tsudoko/anki-sync-server/commit/360b2d08ed37d68741e4497ebe2eeb6755399491 In a nutshell, the SyncRedirector addon doesn't make hostNum empty, resulting in it getting appended to the sync URL. ([1], [2])

kuklinistvan commented 5 years ago

Hey adamwolf,

I was unable to reproduce your issue on Arch Linux and unfortunately I cannot test the behavior on OS X. There are two things that may lead us closer to the solution that you could try in in accordance with the clue tsudoko has provided:

  1. Locate the folder of SyncRedirector and modify SyncRedirector.py according to the patch:
--- SyncRedirector.py
+++ SyncRedirector.py
@@ -1,5 +1,7 @@
 from .Utils import url_ending_with_slash
 import anki.sync
+import anki.hooks
+import aqt

 class SyncRedirector:
@@ -42,3 +44,10 @@
         Expects url ending with /msync or /msync/
         """
         return url_ending_with_slash(self.configured_msync_url) + "%s"
+
+
+def resetHostNum():
+    aqt.mw.pm.profile["hostNum"] = None
+
+
+anki.hooks.addHook("profileLoaded", resetHostNum)

Save the code above as changes.patch in the same folder as SyncRedirector.py and run patch < changes.patch from there. Then, restart Anki and see if it helps. If not, then:

  1. Test the original mean of configuring the synchronization server following the instructions in tsudoko's repository.

Thanks!

adamwolf commented 5 years ago

The patch works perfectly.

kuklinistvan commented 5 years ago

Okay, I have updated the plugin here and at AnkiWeb as well.

Adam, please update your plugin in your Anki Desktop instance and do another test run to see if we can close this issue.

adamwolf commented 5 years ago

The Ankiweb version also works great. Thanks!