Mailman3 experts --
I am trying to subscribe a user to a mailing list via the REST API. This works:
Posting to url http://localhost:8001/3.1/members POST payload: { "list_id": "<LISTID>", "subscriber": "d13b0bbb29844eb9af4b38dad7bb3707", } RESULT post of "http://localhost:8001/3.1/members" succeeds with code 202
This works does *not *work
Posting to url http://localhost:8001/3.1/members POST payload: { "list_id": "<LISTID>", "subscriber": "d13b0bbb29844eb9af4b38dad7bb3707", "pre_approved": true } RESULT post of "http://localhost:8001/3.1/members" fails with code 500
Any suggestions? As best I can tell, inclusion of *any* boolean types in my JSON causes the error code 500. FWIW I am generating the JSON using go language's JSON package.
I noticed in the API doc that the boolean values are represented as 'True' rather than 'true'. So I tried converting all instances of 'true' to 'True' in my encoded json. That produced an http 400 error, as it probably should.
Thanks!
-- Stephen
Followup note: The failed post is associated with this message in mailman.log:
2022-01-18 13:01:49 [FALCON] [ERROR] POST /3.1/members => Traceback (most recent call last): File "falcon/app.py", line 361, in falcon.app.App.__call__ File "/opt/mailman/mm/venv/lib/python3.7/site-packages/mailman/rest/members.py", line 302, in on_post arguments = validator(request) File "/opt/mailman/mm/venv/lib/python3.7/site-packages/mailman/rest/validator.py", line 227, in __call__ values[key] = self._converterskey File "/opt/mailman/mm/venv/lib/python3.7/site-packages/lazr/config/_config.py", line 762, in as_boolean value = value.lower() AttributeError: 'bool' object has no attribute 'lower'
Possible bug in code?
On Tue, Jan 18, 2022 at 1:22 PM Stephen Daniel <swd@pobox.com> wrote:
Mailman3 experts --
I am trying to subscribe a user to a mailing list via the REST API. This works:
Posting to url http://localhost:8001/3.1/members POST payload: { "list_id": "<LISTID>", "subscriber": "d13b0bbb29844eb9af4b38dad7bb3707", } RESULT post of "http://localhost:8001/3.1/members" succeeds with code 202
This works does *not *work
Posting to url http://localhost:8001/3.1/members POST payload: { "list_id": "<LISTID>", "subscriber": "d13b0bbb29844eb9af4b38dad7bb3707", "pre_approved": true } RESULT post of "http://localhost:8001/3.1/members" fails with code 500
Any suggestions? As best I can tell, inclusion of *any* boolean types in my JSON causes the error code 500. FWIW I am generating the JSON using go language's JSON package.
I noticed in the API doc that the boolean values are represented as 'True' rather than 'true'. So I tried converting all instances of 'true' to 'True' in my encoded json. That produced an http 400 error, as it probably should.
Thanks!
-- Stephen
2nd follow-up. Apologies for spamming this list.
I went wandering through the code as suggested by the traceback. I discovered that thee "as_boolean" routine is expecting a string argument but getting a boolean argument.
So, If I send the booleans as strings, with values "true" or "false", all is well. This is not what the API documentation suggests I should do. Can someone either fix the documentation or the code?
Thanks
-- Stephen
On Tue, Jan 18, 2022 at 1:44 PM Stephen Daniel <swd@pobox.com> wrote:
Followup note: The failed post is associated with this message in mailman.log:
2022-01-18 13:01:49 [FALCON] [ERROR] POST /3.1/members => Traceback (most recent call last): File "falcon/app.py", line 361, in falcon.app.App.__call__ File "/opt/mailman/mm/venv/lib/python3.7/site-packages/mailman/rest/members.py", line 302, in on_post arguments = validator(request) File "/opt/mailman/mm/venv/lib/python3.7/site-packages/mailman/rest/validator.py", line 227, in __call__ values[key] = self._converterskey File "/opt/mailman/mm/venv/lib/python3.7/site-packages/lazr/config/_config.py", line 762, in as_boolean value = value.lower() AttributeError: 'bool' object has no attribute 'lower'
Possible bug in code?
On Tue, Jan 18, 2022 at 1:22 PM Stephen Daniel <swd@pobox.com> wrote:
Mailman3 experts --
I am trying to subscribe a user to a mailing list via the REST API. This works:
Posting to url http://localhost:8001/3.1/members POST payload: { "list_id": "<LISTID>", "subscriber": "d13b0bbb29844eb9af4b38dad7bb3707", } RESULT post of "http://localhost:8001/3.1/members" succeeds with code 202
This works does *not *work
Posting to url http://localhost:8001/3.1/members POST payload: { "list_id": "<LISTID>", "subscriber": "d13b0bbb29844eb9af4b38dad7bb3707", "pre_approved": true } RESULT post of "http://localhost:8001/3.1/members" fails with code 500
Any suggestions? As best I can tell, inclusion of *any* boolean types in my JSON causes the error code 500. FWIW I am generating the JSON using go language's JSON package.
I noticed in the API doc that the boolean values are represented as 'True' rather than 'true'. So I tried converting all instances of 'true' to 'True' in my encoded json. That produced an http 400 error, as it probably should.
Thanks!
-- Stephen
On 1/18/22 10:53 AM, Stephen Daniel wrote:
2nd follow-up. Apologies for spamming this list.
I went wandering through the code as suggested by the traceback. I discovered that thee "as_boolean" routine is expecting a string argument but getting a boolean argument.
So, If I send the booleans as strings, with values "true" or "false", all is well. This is not what the API documentation suggests I should do. Can someone either fix the documentation or the code?
Those snippets in the documentation are doctests. That code is actually
executed by unit testing and passes. In all those snippets, dump_json is
passing the second argument as data
to
mailman.testing.documentation.dump_json() which in turn calls
mailman.testing.documentation.call_http() which calls
mailman.testing.helpers.call_api() which ultimately calls
requests.request() with the same data
argument.
So basically, the issue is the difference between how requests.request()
handles that data
dictionary in creating the POST data and whatever
you are doing.
Possibly we could add some caveat to <https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/docs/documentation.html#documentation-helpers> or possibly elsewhere. Do you have a suggestion as to what?
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
The REST API documentation is a bit informal. As someone who is not familiar with mailman, and who doesn't know python, they are a bit of a slog.
One day it would be nice to augment the documentation with a formal and complete reference document. Something like this one <https://infosight.hpe.com/InfoSight/media/cms/active/public/pubs_REST_API_Reference_NOS_51x.whz/jun1455055569904.html>. A formal reference manual needs a complete listing of every type of object, all possible operations on each object, and all required and optional parameters.
Since creating a formal document like that is probably out of scope, at a minimum it would be good to specify that boolean values are passed as JSON strings, not JSON booleans.
It might be worth seeing if the code can be enhanced to allow the boolean values to be sent in using JSON booleans as well as JSON strings.
Thanks again for the prompt response!
-- Stephen
On Tue, Jan 18, 2022 at 4:25 PM Mark Sapiro <mark@msapiro.net> wrote:
On 1/18/22 10:53 AM, Stephen Daniel wrote:
2nd follow-up. Apologies for spamming this list.
I went wandering through the code as suggested by the traceback. I discovered that thee "as_boolean" routine is expecting a string argument but getting a boolean argument.
So, If I send the booleans as strings, with values "true" or "false", all is well. This is not what the API documentation suggests I should do. Can someone either fix the documentation or the code?
Those snippets in the documentation are doctests. That code is actually executed by unit testing and passes. In all those snippets, dump_json is passing the second argument as
data
to mailman.testing.documentation.dump_json() which in turn calls mailman.testing.documentation.call_http() which calls mailman.testing.helpers.call_api() which ultimately calls requests.request() with the samedata
argument.So basically, the issue is the difference between how requests.request() handles that
data
dictionary in creating the POST data and whatever you are doing.Possibly we could add some caveat to < https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/docs/documentation.html#documentation-helpers>
or possibly elsewhere. Do you have a suggestion as to what?
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mailman-users mailing list -- mailman-users@mailman3.org To unsubscribe send an email to mailman-users-leave@mailman3.org https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/
On 1/18/22 2:11 PM, Stephen Daniel wrote:
The REST API documentation is a bit informal. As someone who is not familiar with mailman, and who doesn't know python, they are a bit of a slog.
Agreed. I guess we sort of assume that people dealing directly with the REST API are familiar with both.
It might be worth seeing if the code can be enhanced to allow the boolean values to be sent in using JSON booleans as well as JSON strings.
I think here we only have to deal with the REST API because other uses of as_boolean are all on strings that come from config files. We can't modify as_boolean directly, as it is part of a third party dependency and is intended to be used with config files, not JSON objects, but I think something like this will do it. ``` --- a/src/mailman/rest/helpers.py +++ b/src/mailman/rest/helpers.py @@ -249,6 +249,8 @@ class GetterSetter: """ if self.decoder is None: return value + if self.decoder is as_boolean and isinstance(value, bool): + return value return self.decoder(value) ``` Perhaps you could try to test that. I just created https://gitlab.com/mailman/mailman/-/issues/970 for this. It would help me in fixing this if you could provide a small piece of your code that throws the error. -- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
I can give you a program written in Go. Would that be helpful? On Tue, Jan 18, 2022 at 6:49 PM Mark Sapiro <mark@msapiro.net> wrote:
On 1/18/22 2:11 PM, Stephen Daniel wrote:
The REST API documentation is a bit informal. As someone who is not familiar with mailman, and who doesn't know python, they are a bit of a slog.
Agreed. I guess we sort of assume that people dealing directly with the REST API are familiar with both.
It might be worth seeing if the code can be enhanced to allow the boolean values to be sent in using JSON booleans as well as JSON strings.
I think here we only have to deal with the REST API because other uses of as_boolean are all on strings that come from config files. We can't modify as_boolean directly, as it is part of a third party dependency and is intended to be used with config files, not JSON objects, but I think something like this will do it. ``` --- a/src/mailman/rest/helpers.py +++ b/src/mailman/rest/helpers.py @@ -249,6 +249,8 @@ class GetterSetter: """ if self.decoder is None: return value + if self.decoder is as_boolean and isinstance(value, bool): + return value return self.decoder(value)
``` Perhaps you could try to test that.
I just created https://gitlab.com/mailman/mailman/-/issues/970 for this. It would help me in fixing this if you could provide a small piece of your code that throws the error.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan _______________________________________________ Mailman-users mailing list -- mailman-users@mailman3.org To unsubscribe send an email to mailman-users-leave@mailman3.org https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/
On 1/18/22 3:54 PM, Stephen Daniel wrote:
I can give you a program written in Go. Would that be helpful?
It may be. Send it off list and I'll see.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mark Sapiro writes:
Agreed. I guess we sort of assume that people dealing directly with the REST API are familiar with both [Mailman and Python].
Empathy and Affinity are PHP applications (although I think we can assume that Brian provided the Mailman knowledge if the programmer didn't have it). I think we should assume that there are a lot (in dozens) of folks out there thinking about accessing Mailman's REST API from various languages, although I suspect most are familiar with Mailman.
Steve
participants (3)
-
Mark Sapiro
-
Stephen Daniel
-
Stephen J. Turnbull