Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

<class 'TypeError'>: Object of type 'map' is not JSON serializable #85

Closed
517qf opened this issue Jun 25, 2018 · 9 comments · Fixed by #88
Closed

<class 'TypeError'>: Object of type 'map' is not JSON serializable #85

517qf opened this issue Jun 25, 2018 · 9 comments · Fixed by #88

Comments

@517qf
Copy link

517qf commented Jun 25, 2018

I tried with beta 42 and the latest AnkiConnect from 2018-06-24. This is the only addon installed. I don't call AnkiConnect directly but from within an emacs package that's called anki-editor. This package allows to send/push notes to AnkiConnect. When I run the "push" command in this package I get the following error message in Anki.

This emacs package works fine with AnkiConnect in 2.0.52. So I assume that the problem is not with this emacs-package? I don't know about the internals of emacs/elisp so I can't tell you what exactly is sent to AnkiConnect. Nevertheless I decided to post because this error message might still be useful for you ? If you feel that a novice like me can help with further information just give me instructions on what to do.

Anyway thanks for your great software.


Debug info:
Anki 2.1.0beta42 Python 3.6.2 Qt 5.9.2 PyQt 5.9
Platform: Linux
Flags: frz=True ao=True sv=1

Caught exception:
  File "/the/path/to/profile/addons21/2055492159/__init__.py", line 293, in advance
    self.server.advance()
  File "/the/path/to/profile/addons21/2055492159/__init__.py", line 204, in advance
    self.advanceClients()
  File "/the/path/to/profile/addons21/2055492159/__init__.py", line 219, in advanceClients
    self.clients = list(filter(lambda c: c.advance(), self.clients))
  File "/the/path/to/profile/addons21/2055492159/__init__.py", line 219, in <lambda>
    self.clients = list(filter(lambda c: c.advance(), self.clients))
  File "/the/path/to/profile/addons21/2055492159/__init__.py", line 126, in advance
    self.writeBuff += self.handler(req)
  File "/the/path/to/profile/addons21/2055492159/__init__.py", line 238, in handlerWrapper
    body = makeBytes(json.dumps(self.handler(params)))
  File "json/__init__.py", line 231, in dumps
  File "json/encoder.py", line 199, in encode
  File "json/encoder.py", line 257, in iterencode
  File "json/encoder.py", line 180, in default
<class 'TypeError'>: Object of type 'map' is not JSON serializable
@FooSoft
Copy link
Owner

FooSoft commented Jun 28, 2018

So it looks like AnkiConnect is getting passed some request that is causing it to generate a response which cannot be serialized to JSON. From the call stack it's kind of hard to figure out what's going on (since the actual handler is not displayed). Would mind running a modified AnkiConnect plugin to help troubleshoot this issue?

@517qf
Copy link
Author

517qf commented Jun 28, 2018

Thank you very much for the quick answer to such an incomplete error report. I'll try my best to help. Where do you I find the modfified version?

@FooSoft
Copy link
Owner

FooSoft commented Jun 30, 2018

Hey, so I just added a basic API logging feature and uploaded a new version of AnkiConnect it to AnkiWeb (you can update the plugin from there). If you open the AnkiConnect.py`, near the top you will find this line:

API_LOG_PATH = None

If you change that to have a file path in there (in quotes), all of the transactions between emacs and Anki should be logged in there. So for instance you could do something like:

API_LOG_PATH = 'ankiconnect_log.txt'

If you post the contents of that text file into this issue, it should hopefully provide enough context about what is going on to fix this problem 👍

@517qf
Copy link
Author

517qf commented Jun 30, 2018

Thanks again for your help.

I tried but failed. I only get an empty file that has the name I set for the variable API_LOG_PATH (I just copied the code you posted). I used cat ankiconnect_log.txt and there was no output. I used the latest beta 42 for 2.1 with the most recent version from AnkiWeb. To be on the safe side I deleted all addons and then downloaded Ankiconnect.

I still get the error report I reported in the initial post.

Don't put too much trust into my reports. I'm afraid my motivation is higher than my knowledge. But I'm open to any new tasks ...

@FooSoft
Copy link
Owner

FooSoft commented Jul 1, 2018

I guess I should have mentioned that after you set the log file path, you should perform the action that causes AnkiConnect to misbehave.

Nothing will be logged if you just run Anki and don't actually use AnkiConnect to talk with an external program : )

@517qf
Copy link
Author

517qf commented Jul 1, 2018

Thanks your time. I think I did what you asked for: I sent notes to AnkiConnect from this external application but didn't get a log.

To make sure that logging works or I don't make a mistake I just tried a different software that talks to AnkiConnect. Still I can't get a log reliably. I used the Chrome Extension Anki Quick Adder
.

Here's a video of what I did:
ankiconnect_

Once I got a log for the chrome extension (and I think with exactly the same procedure). But I don't know what I did differently than in the run I've shown and I can't replicate it. Did I do something wrong?

@FooSoft
Copy link
Owner

FooSoft commented Jul 7, 2018

Thanks for the vid and sorry about the slow reply -- has been a hectic week. Since it looks like you are running on Debian (Linux makes everything easier), you can just change the self.log.write statements in the AnkiConnect source file to print and just have them go out to standard out in console, from where you can copy-paste them here. I have no idea why logging to file does not appear to be working correctly on your machine 😕

@517qf
Copy link
Author

517qf commented Jul 8, 2018

I think a reply within one week for an open source project that you do in your free time is very good.

I experimented today, this time with a virtual machine that contains ubuntu mate 18.04. I can't get ankiconnect to write into a file or to stdout. I replaced self.log.write(...) with print(...) but didn't get anything.

the most obvious thing these two cases have in common is the user. So I guess that I make some kind of mistake or have some misconfiguration that I'm not aware of. 2.0.52 works so I'm in a very good position. Maybe the most efficient thing is to just wait and hope that some future version (for whatever reasons) just works.

If you feel that I can do something let me know but I'm afraid that I'm just wasting your time. Again thank you very much for your great software and extensive help.

@louietan
Copy link
Contributor

louietan commented Jul 29, 2018

I suppose it's introduced by 7a0b4e6, which replaces for loop with
map, the return value of which is a list in python 2, but an iterator in 3 that can't be serialized, to make it to work, we seem to have to copy it to a list anyway, I'll make a PR for this.

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

Successfully merging a pull request may close this issue.

3 participants