Discussion:
[mb-devel] Help with 400 Bad Request
Joe Martinez
2015-02-15 01:44:40 UTC
Permalink
I'm attempting to write a client library to send ratings to MusicBrainz.
There is no existing client library for my environment (c#) that supports
sending ratings, so I am attempting to write my own.

Here's the info about my http request:

URL = http://musicbrainz.org/ws/2/rating?client=MyGrooves-0.0.1

Method: POST

Request Headers:
UserAgent = JmmRater/1.0.0 ( ***@jmmsoftware.com )

Content Headers:
Content-Type = application/xml; charset=utf-8

Content:
<?xml version="1.0" encoding="UTF-8"?> <metadata xmlns="
http://musicbrainz.org/ns/mmd-2.0#">
<recording-list>
<recording
id="f5aec1b4-0162-489b-ad1a-2aeecebc7d8a">
<user-rating>4</user-rating>
</recording>
</recording-list>
</metadata>

I am sending Digest authentication credentials.

When I send this, I am getting a status code of 400 Bad Request.
The content of the response is blank.

I'm not sure where to go from here. Does anyone see anything above that
points to what I'm doing wrong? If not, how can I debug this?

Thanks,
Joe
Ian McEwen
2015-02-15 03:47:18 UTC
Permalink
I'm looking now.

The only thing that stands out to me is that ratings are numbers
between 0 and 100. I'm assuming you meant four stars, which would be 80,
not 4.

I'm not sure what exact process/tools you're using for submission since
I'm unfamiliar with C#, but it works fine with me with, at the command
line:

curl --header "Content-Type: application/xml;charset=utf-8" -X POST --digest --user username:password -d @rate.xml http://musicbrainz.org/ws/2/rating?client=ianmcorvidae-0.0.1

where username/password obviously get replaced and rate.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
<recording-list>
<recording id="f5aec1b4-0162-489b-ad1a-2aeecebc7d8a">
<user-rating>80</user-rating>
</recording>
</recording-list>
</metadata>

However, this also works fine with 4 rather than 80, though the result
on the site is that it appears to be unrated, since that's less than 1
star.

Looking at the code, most normal errors should return an XML document
with the error, e.g. if I change 'recording' to 'event' (since events
can't be rated), I get:

<?xml version="1.0" encoding="UTF-8"?><error><text>Entity type 'event'
cannot have ratings. Supported types are: artist, recording, work,
release-group, label</text><text>For usage, please see:
http://musicbrainz.org/development/mmd</text></error>

One thing I might check is how your C# tools handle response bodies for
this sort of request -- perhaps it's throwing out the response that
would tell you what's wrong?

So, I'm not really sure what might be wrong, I guess :( hopefully something in
there helps. One other small thing I notice is that you're giving a
different client in the URL vs. the user-agent, which I'm guessing isn't
intentional.

Hope you find out what's wrong!
Post by Joe Martinez
I'm attempting to write a client library to send ratings to MusicBrainz.
There is no existing client library for my environment (c#) that supports
sending ratings, so I am attempting to write my own.
URL = http://musicbrainz.org/ws/2/rating?client=MyGrooves-0.0.1
Method: POST
Content-Type = application/xml; charset=utf-8
<?xml version="1.0" encoding="UTF-8"?> <metadata xmlns="
http://musicbrainz.org/ns/mmd-2.0#">
<recording-list>
<recording
id="f5aec1b4-0162-489b-ad1a-2aeecebc7d8a">
<user-rating>4</user-rating>
</recording>
</recording-list>
</metadata>
I am sending Digest authentication credentials.
When I send this, I am getting a status code of 400 Bad Request.
The content of the response is blank.
I'm not sure where to go from here. Does anyone see anything above that
points to what I'm doing wrong? If not, how can I debug this?
Thanks,
Joe
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 04:48:32 UTC
Permalink
Post by Ian McEwen
However, this also works fine with 4 rather than 80, though the result
on the site is that it appears to be unrated, since that's less than 1
star.
Actually, the rating is visible - the left edge of the first star has
a tiny blue dot:
http://chirlu.mbsandbox.org/recording/f5aec1b4-0162-489b-ad1a-2aeecebc7d8a/ratings
So as you see, it worked for me, too.
Post by Ian McEwen
Looking at the code, most normal errors should return an XML document
with the error, e.g. if I change 'recording' to 'event' (since events
This is a bug, BTW, because events do have ratings. I'll make it use
%ENTITIES instead of the outdated hardcoded list.

Ulrich
Ian McEwen
2015-02-15 04:59:41 UTC
Permalink
Post by Ulrich Klauer
Post by Ian McEwen
However, this also works fine with 4 rather than 80, though the result
on the site is that it appears to be unrated, since that's less than 1
star.
Actually, the rating is visible - the left edge of the first star has
http://chirlu.mbsandbox.org/recording/f5aec1b4-0162-489b-ad1a-2aeecebc7d8a/ratings
So as you see, it worked for me, too.
Ah. I couldn't see it in the yellow color for my own rating, I think. Or
perhaps I wasn't looking hard enough. Anyway, it still largely does
appear unrated, especially on small screens ;)
Post by Ulrich Klauer
Post by Ian McEwen
Looking at the code, most normal errors should return an XML document
with the error, e.g. if I change 'recording' to 'event' (since events
This is a bug, BTW, because events do have ratings. I'll make it use
%ENTITIES instead of the outdated hardcoded list.
Heh, I was thinking exactly that as I looked at it. Didn't occur to me
that it might *already* be wrong though.
Post by Ulrich Klauer
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Joe Martinez
2015-02-15 05:20:03 UTC
Permalink
Ian,

Thanks for the response. See my responses below...
Post by Ian McEwen
I'm looking now.
The only thing that stands out to me is that ratings are numbers
between 0 and 100. I'm assuming you meant four stars, which would be 80,
not 4.
Yes, I was doing it based on a 0-5 rating. I did that based on this page:

https://musicbrainz.org/doc/Rating_System

Do you know why it says 0-5, when it's really 0-100? Or, is that page
talking about something altogether different?
Post by Ian McEwen
I'm not sure what exact process/tools you're using for submission since
I'm unfamiliar with C#, but it works fine with me with, at the command
curl --header "Content-Type: application/xml;charset=utf-8" -X POST
http://musicbrainz.org/ws/2/rating?client=ianmcorvidae-0.0.1
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
<recording-list>
<recording id="f5aec1b4-0162-489b-ad1a-2aeecebc7d8a">
<user-rating>80</user-rating>
</recording>
</recording-list>
</metadata>
Ok, so it sounds like the problem isn't with my XML at least. Must be
something else in what I'm doing.
Post by Ian McEwen
Looking at the code, most normal errors should return an XML document
with the error, e.g. if I change 'recording' to 'event' (since events
<?xml version="1.0" encoding="UTF-8"?><error><text>Entity type 'event'
cannot have ratings. Supported types are: artist, recording, work,
http://musicbrainz.org/development/mmd</text></error>
One thing I might check is how your C# tools handle response bodies for
this sort of request -- perhaps it's throwing out the response that
would tell you what's wrong?
Well, the interesting thing is that when I have other errors, I DO get
something back.

Here's an example: If I leave out the User-Agent header, I get a Status
Code of 503 Service Unavailable, and the response body says:

<?xml version="1.0" encoding="UTF-8"?><error><text>Your requests are being
throttled by MusicBrainz because the application you are using has not
identified itself. Please update your application, and see
http://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting for more
information.</text><text>For usage, please see:
http://musicbrainz.org/development/mmd</text></error>

So, I'm definitely looking in the right place. If I add the User-Agent
header back in, then again, I get a response status code of 400 Bad
Request, and an empty response body.

So, I'm not really sure what might be wrong, I guess :( hopefully something
Post by Ian McEwen
in
there helps. One other small thing I notice is that you're giving a
different client in the URL vs. the user-agent, which I'm guessing isn't
intentional.
Actually, it is intentional. From what I saw in the documentation, it
looks like User-Agent refers to the name/version of the client library, and
the client in the URL refers to the end user application.

On this page:
https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#Submitting_data

it says:
"POST requests should always include a 'client' parameter in the URL (not
the body). The value of 'client' should be the ID of the client software
submitting data. This has to be the application's name and version number,
not that of a client library (client libraries should use HTTP's User-Agent
header). The recommended format is "application-version", where version
does not contain a - character."

Did I misinterpret that?
Post by Ian McEwen
Hope you find out what's wrong!
Me too! I don't suppose there's a way I could send the response to a test
server that someone can look at and tell me what they see wrong on the
server side?

Thanks,
Joe
Ulrich Klauer
2015-02-15 05:32:25 UTC
Permalink
Post by Joe Martinez
https://musicbrainz.org/doc/Rating_System
Do you know why it says 0-5, when it's really 0-100? Or, is that page
talking about something altogether different?
Outdated, I guess. It's also still speaking about ws/1.
Post by Joe Martinez
I don't suppose there's a way I could send the response to a test
server that someone can look at and tell me what they see wrong on the
server side?
You can use chirlu.mbsandbox.org (passwords are "mb" for all user accounts).

Ulrich
Joe Martinez
2015-02-15 06:49:07 UTC
Permalink
Ulrich,

I just sent one to your sandbox. I got the same response as the production
server (400 Bad Request, with nothing in the response body). Can you see
anything on your end?

-Joe
Post by Ulrich Klauer
Post by Joe Martinez
Yes, I was doing it based on a 0-5 rating. I did that based on this
https://musicbrainz.org/doc/Rating_System
Do you know why it says 0-5, when it's really 0-100? Or, is that page
talking about something altogether different?
Outdated, I guess. It's also still speaking about ws/1.
Post by Joe Martinez
I don't suppose there's a way I could send the response to a test
server that someone can look at and tell me what they see wrong on the
server side?
You can use chirlu.mbsandbox.org (passwords are "mb" for all user accounts).
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 07:15:09 UTC
Permalink
Post by Joe Martinez
I just sent one to your sandbox. I got the same response as the production
server (400 Bad Request, with nothing in the response body). Can you see
anything on your end?
I see the requests (one with 401 Authorization Required, then the 400
Bad Request) and can confirm that the response body is empty. There is
no warning or other message, though. Your latest attempt at 07:07 UTC
was just a single request with a 401.

I added some debug statements, so could you try again?

Ulrich
Joe Martinez
2015-02-15 07:24:57 UTC
Permalink
Ok, done.

-Joe
Post by Joe Martinez
Post by Joe Martinez
I just sent one to your sandbox. I got the same response as the
production
Post by Joe Martinez
server (400 Bad Request, with nothing in the response body). Can you see
anything on your end?
I see the requests (one with 401 Authorization Required, then the 400
Bad Request) and can confirm that the response body is empty. There is
no warning or other message, though. Your latest attempt at 07:07 UTC
was just a single request with a 401.
I added some debug statements, so could you try again?
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 07:37:49 UTC
Permalink
Post by Joe Martinez
Ok, done.
One more time, please?

Ulrich
Joe Martinez
2015-02-15 07:38:54 UTC
Permalink
ok, done again
Post by Ulrich Klauer
Post by Joe Martinez
Ok, done.
One more time, please?
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Joe Martinez
2015-02-15 07:43:15 UTC
Permalink
Just realized that my last couple sends were missing the User-Agent
header. Just sent again with that header added back in.
Post by Joe Martinez
ok, done again
Post by Ulrich Klauer
Post by Joe Martinez
Ok, done.
One more time, please?
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 07:43:52 UTC
Permalink
Post by Joe Martinez
ok, done again
OK, found the right place where to look. :-) Currently, you are not
sending an XML document, but a file name. I.e. the request body is
something like "/tmp/gBqzJCJkqK" when you probably want to send the
contents of that file.

You should fix that, then try again so that we can catch any other
problems while the debugging code is still there.

Ulrich
Joe Martinez
2015-02-15 07:45:32 UTC
Permalink
ok, 1 sec, I'll check that.
Post by Ulrich Klauer
Post by Joe Martinez
ok, done again
OK, found the right place where to look. :-) Currently, you are not
sending an XML document, but a file name. I.e. the request body is
something like "/tmp/gBqzJCJkqK" when you probably want to send the
contents of that file.
You should fix that, then try again so that we can catch any other
problems while the debugging code is still there.
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Joe Martinez
2015-02-15 07:52:53 UTC
Permalink
Are you sure about that? I checked the code, and I can't seen how that
would be happening. I'm not even writing the document to a file. I'm
creating it as a string in memory and sending it directly from memory.
Also, that path that you mentioned looks like a Unix path, and I'm on a
Window system, so even if I was, it would start with "C:\", rather than
"/tmp/".

Could you be looking at the wrong request?

-Joe
Post by Ulrich Klauer
Post by Joe Martinez
ok, done again
OK, found the right place where to look. :-) Currently, you are not
sending an XML document, but a file name. I.e. the request body is
something like "/tmp/gBqzJCJkqK" when you probably want to send the
contents of that file.
You should fix that, then try again so that we can catch any other
problems while the debugging code is still there.
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 08:51:21 UTC
Permalink
Post by Joe Martinez
Are you sure about that? I checked the code, and I can't seen how that
would be happening. I'm not even writing the document to a file. I'm
creating it as a string in memory and sending it directly from memory.
Also, that path that you mentioned looks like a Unix path, and I'm on a
Window system, so even if I was, it would start with "C:\", rather than
"/tmp/".
Could you be looking at the wrong request?
It's the right request, but it's true that the file name is local. It
seems Catalyst puts the data into a temporary file in some cases.

I'm trying to read it from the tempfile if that happens now, but I'm
not sure it works. Try again, anyway ...

Ulrich
Joe Martinez
2015-02-15 09:05:31 UTC
Permalink
Ok, I just sent two more. The first one was missing the "?client..." part
of the URL, and I got an authorization error. The second one had the
"?client..." part in the URL, and I got the Bad Request again, with an
empty body.
Post by Ulrich Klauer
Post by Joe Martinez
Are you sure about that? I checked the code, and I can't seen how that
would be happening. I'm not even writing the document to a file. I'm
creating it as a string in memory and sending it directly from memory.
Also, that path that you mentioned looks like a Unix path, and I'm on a
Window system, so even if I was, it would start with "C:\", rather than
"/tmp/".
Could you be looking at the wrong request?
It's the right request, but it's true that the file name is local. It
seems Catalyst puts the data into a temporary file in some cases.
I'm trying to read it from the tempfile if that happens now, but I'm
not sure it works. Try again, anyway ...
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 09:59:51 UTC
Permalink
Post by Joe Martinez
Ok, I just sent two more. The first one was missing the "?client..." part
of the URL, and I got an authorization error. The second one had the
"?client..." part in the URL, and I got the Bad Request again, with an
empty body.
It seems the issue might be in the URI used for calculating the
digest. The header was:

Authorization: Digest
username="jmartine",realm="musicbrainz.org",nonce="9SeEag2TSsSWn5OpDa/C0Q==",uri="/ws/2/rating",algorithm="MD5",cnonce="a1f74260843b54d3b773c4bf84b7ae5c",nc=00000001,qop="auth",response="8086d2cbc3bb9b20425f9a66f5443e98",opaque="W01Tt4kCQ+qOe2Oo6O6vGg=="

At the same time, the actual request was for
/ws/2/rating?client=StarMyGrooves-1.0, so that is what the uri part in
Authorization should be.

With that, I found this SO question:
http://stackoverflow.com/questions/3109507
It seems it is a bug in .NET; there is mention of a bug report to
Microsoft Connect in the comments on the accepted answer, but I can't
access it (requires some account). The original poster solved it by
reimplementing digest auth themselves.

Ulrich
Joe Martinez
2015-02-15 10:07:20 UTC
Permalink
Actually, while I was waiting, I found that same SO question, and
implemented that workaround. I just sent another request, using the
workaround. This time, I got "Authorization required." in the body. Can
you check that one?
Post by Ulrich Klauer
Post by Joe Martinez
Ok, I just sent two more. The first one was missing the "?client..."
part
Post by Joe Martinez
of the URL, and I got an authorization error. The second one had the
"?client..." part in the URL, and I got the Bad Request again, with an
empty body.
It seems the issue might be in the URI used for calculating the
Authorization: Digest
username="jmartine",realm="musicbrainz.org
",nonce="9SeEag2TSsSWn5OpDa/C0Q==",uri="/ws/2/rating",algorithm="MD5",cnonce="a1f74260843b54d3b773c4bf84b7ae5c",nc=00000001,qop="auth",response="8086d2cbc3bb9b20425f9a66f5443e98",opaque="W01Tt4kCQ+qOe2Oo6O6vGg=="
At the same time, the actual request was for
/ws/2/rating?client=StarMyGrooves-1.0, so that is what the uri part in
Authorization should be.
http://stackoverflow.com/questions/3109507
It seems it is a bug in .NET; there is mention of a bug report to
Microsoft Connect in the comments on the accepted answer, but I can't
access it (requires some account). The original poster solved it by
reimplementing digest auth themselves.
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 10:19:40 UTC
Permalink
Post by Joe Martinez
Actually, while I was waiting, I found that same SO question, and
implemented that workaround. I just sent another request, using the
workaround. This time, I got "Authorization required." in the body. Can
you check that one?
Post by Ulrich Klauer
Authorization: Digest
username="jmartine",realm="musicbrainz.org",nonce="9SeEag2TSsSWn5OpDa/C0Q==",uri="/ws/2/rating",algorithm="MD5",cnonce="a1f74260843b54d3b773c4bf84b7ae5c",nc=00000001,qop="auth",response="8086d2cbc3bb9b20425f9a66f5443e98",opaque="W01Tt4kCQ+qOe2Oo6O6vGg=="
This is the new one:

Authorization: Digest username="jmartine", realm="musicbrainz.org",
nonce="ot3KqbreS0mgD/O/Eqij4w==",
uri="/ws/2/rating?client=StarMyGrooves-1.0", algorithm=MD5,
response="28da1f0ed9c2647561f7732d92eea1d2", qop=auth,auth-int,
nc=00000001, cnonce="2615318"

The immediate problem seems to be that opaque is missing (it should
echo the value sent from the server), but having "auth,auth-int" seems
also suspicious.

Ulrich
Joe Martinez
2015-02-15 10:35:28 UTC
Permalink
Ok, I updated it to echo the opaque value sent from the server. I sent it
to your server again, and I got the same error.
Post by Ulrich Klauer
Post by Joe Martinez
Actually, while I was waiting, I found that same SO question, and
implemented that workaround. I just sent another request, using the
workaround. This time, I got "Authorization required." in the body. Can
you check that one?
Post by Ulrich Klauer
Authorization: Digest
username="jmartine",realm="musicbrainz.org
",nonce="9SeEag2TSsSWn5OpDa/C0Q==",uri="/ws/2/rating",algorithm="MD5",cnonce="a1f74260843b54d3b773c4bf84b7ae5c",nc=00000001,qop="auth",response="8086d2cbc3bb9b20425f9a66f5443e98",opaque="W01Tt4kCQ+qOe2Oo6O6vGg=="
Authorization: Digest username="jmartine", realm="musicbrainz.org",
nonce="ot3KqbreS0mgD/O/Eqij4w==",
uri="/ws/2/rating?client=StarMyGrooves-1.0", algorithm=MD5,
response="28da1f0ed9c2647561f7732d92eea1d2", qop=auth,auth-int,
nc=00000001, cnonce="2615318"
The immediate problem seems to be that opaque is missing (it should
echo the value sent from the server), but having "auth,auth-int" seems
also suspicious.
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Joe Martinez
2015-02-15 10:45:44 UTC
Permalink
I also noticed that there were some quotes missing in the authorization,
and fixed them as well. The last one I sent should be the best so far.
Still getting the error though.
Post by Joe Martinez
Ok, I updated it to echo the opaque value sent from the server. I sent it
to your server again, and I got the same error.
Post by Ulrich Klauer
Post by Joe Martinez
Actually, while I was waiting, I found that same SO question, and
implemented that workaround. I just sent another request, using the
workaround. This time, I got "Authorization required." in the body.
Can
Post by Joe Martinez
you check that one?
Post by Ulrich Klauer
Authorization: Digest
username="jmartine",realm="musicbrainz.org
",nonce="9SeEag2TSsSWn5OpDa/C0Q==",uri="/ws/2/rating",algorithm="MD5",cnonce="a1f74260843b54d3b773c4bf84b7ae5c",nc=00000001,qop="auth",response="8086d2cbc3bb9b20425f9a66f5443e98",opaque="W01Tt4kCQ+qOe2Oo6O6vGg=="
Authorization: Digest username="jmartine", realm="musicbrainz.org",
nonce="ot3KqbreS0mgD/O/Eqij4w==",
uri="/ws/2/rating?client=StarMyGrooves-1.0", algorithm=MD5,
response="28da1f0ed9c2647561f7732d92eea1d2", qop=auth,auth-int,
nc=00000001, cnonce="2615318"
The immediate problem seems to be that opaque is missing (it should
echo the value sent from the server), but having "auth,auth-int" seems
also suspicious.
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 10:48:38 UTC
Permalink
Post by Joe Martinez
Ok, I updated it to echo the opaque value sent from the server. I sent it
to your server again, and I got the same error.
It's a real authentication error this time. :-) The account jmartine
doesn't exist on the sandbox as it is too young. Use something else
(like "foo", that does exist), or try it on the real server (with your
real password then, of course).

Though for good measure, you should change the qop value; I checked
with the RFC, and it indeed may only be one value - the server
provides a list of options to choose from (auth, auth-int) and you
send only the selected option (auth).

Ulrich
Joe Martinez
2015-02-15 11:01:49 UTC
Permalink
Ok, I changed the user to "foo", and changed the qop value to just "auth".
I still get the same error. I tried on the real server with my real
username and password, and got the same error as well.
Post by Ulrich Klauer
Post by Joe Martinez
Ok, I updated it to echo the opaque value sent from the server. I sent
it
Post by Joe Martinez
to your server again, and I got the same error.
It's a real authentication error this time. :-) The account jmartine
doesn't exist on the sandbox as it is too young. Use something else
(like "foo", that does exist), or try it on the real server (with your
real password then, of course).
Though for good measure, you should change the qop value; I checked
with the RFC, and it indeed may only be one value - the server
provides a list of options to choose from (auth, auth-int) and you
send only the selected option (auth).
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 11:10:55 UTC
Permalink
Post by Joe Martinez
Ok, I changed the user to "foo", and changed the qop value to just "auth".
I still get the same error. I tried on the real server with my real
username and password, and got the same error as well.
There may be an error in the digest auth (re)implementation. Here's
one of the headers:

Authorization: Digest username="foo", realm="musicbrainz.org",
nonce="0SrG013lQXGx4D+kSt+MKA==",
uri="/ws/2/rating?client=StarMyGrooves-1.0", algorithm=MD5,
response="5bad0672d2471db82fcbe2458dadd97d", qop="auth",
nc="00000001", cnonce="4498083", opaque="iya2HDCZRt2MaQ0ItxKNHg=="

When I calculate what the response should be, I get:
$ echo -n 'foo:musicbrainz.org:mb' | md5sum -
da514dfb6ce7e1c7a7f96c43058afce1 -
$ echo -n 'POST:/ws/2/rating?client=StarMyGrooves-1.0' | md5sum -
ff66f61b71a315cccce4812e96a65e84 -
$ echo -n
'da514dfb6ce7e1c7a7f96c43058afce1:0SrG013lQXGx4D+kSt+MKA==:00000001:4498083:auth:ff66f61b71a315cccce4812e96a65e84' | md5sum
-
9076ea78ed724151ad0f5ec046f4a348 -

However, the response is 5bad067..., not 9076ea7...

Ulrich
Joe Martinez
2015-02-15 11:30:40 UTC
Permalink
Yes!!!!!! I finally got an "OK" response! The final problem was that I
had changed the qop value in the qop field itself in the Digest, but I
didn't change it in the MD5 hash computation, so they didn't match. I
changed it there, and it worked!

I then changed to the production server with my real username and password,
and got an "OK" response. I checked the website, and my rating is now
showing there!

Thank you! Thank you! Thank you!!!! I never could have figured this out
without your help!

All this was due to a stupid bug in .NET, and also some bugs in the posted
workaround.

I'm so happy! Once I get this all smoothed out, I'll be sure and submit my
client provider for the MusicBrainz website so others can use it.

Thanks again!

-Joe
Post by Joe Martinez
Post by Joe Martinez
Ok, I changed the user to "foo", and changed the qop value to just
"auth".
Post by Joe Martinez
I still get the same error. I tried on the real server with my real
username and password, and got the same error as well.
There may be an error in the digest auth (re)implementation. Here's
Authorization: Digest username="foo", realm="musicbrainz.org",
nonce="0SrG013lQXGx4D+kSt+MKA==",
uri="/ws/2/rating?client=StarMyGrooves-1.0", algorithm=MD5,
response="5bad0672d2471db82fcbe2458dadd97d", qop="auth",
nc="00000001", cnonce="4498083", opaque="iya2HDCZRt2MaQ0ItxKNHg=="
$ echo -n 'foo:musicbrainz.org:mb' | md5sum -
da514dfb6ce7e1c7a7f96c43058afce1 -
$ echo -n 'POST:/ws/2/rating?client=StarMyGrooves-1.0' | md5sum -
ff66f61b71a315cccce4812e96a65e84 -
$ echo -n
'da514dfb6ce7e1c7a7f96c43058afce1:0SrG013lQXGx4D+kSt+MKA==:00000001:4498083:auth:ff66f61b71a315cccce4812e96a65e84'
| md5sum
-
9076ea78ed724151ad0f5ec046f4a348 -
However, the response is 5bad067..., not 9076ea7...
Ulrich
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ian McEwen
2015-02-15 05:46:46 UTC
Permalink
Post by Joe Martinez
Ian,
Thanks for the response. See my responses below...
Post by Ian McEwen
I'm looking now.
The only thing that stands out to me is that ratings are numbers
between 0 and 100. I'm assuming you meant four stars, which would be 80,
not 4.
https://musicbrainz.org/doc/Rating_System
Do you know why it says 0-5, when it's really 0-100? Or, is that page
talking about something altogether different?
It's somewhat misleading -- the site only lets people set multiples of
20 (i.e., 1-5 "stars"), but on the backend it's 1-100.

https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#ratings
is fairly sparse but as you can see the example uses 20, which is
clearly not 1-5.
Post by Joe Martinez
Post by Ian McEwen
I'm not sure what exact process/tools you're using for submission since
I'm unfamiliar with C#, but it works fine with me with, at the command
curl --header "Content-Type: application/xml;charset=utf-8" -X POST
http://musicbrainz.org/ws/2/rating?client=ianmcorvidae-0.0.1
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
<recording-list>
<recording id="f5aec1b4-0162-489b-ad1a-2aeecebc7d8a">
<user-rating>80</user-rating>
</recording>
</recording-list>
</metadata>
Ok, so it sounds like the problem isn't with my XML at least. Must be
something else in what I'm doing.
Post by Ian McEwen
Looking at the code, most normal errors should return an XML document
with the error, e.g. if I change 'recording' to 'event' (since events
<?xml version="1.0" encoding="UTF-8"?><error><text>Entity type 'event'
cannot have ratings. Supported types are: artist, recording, work,
http://musicbrainz.org/development/mmd</text></error>
One thing I might check is how your C# tools handle response bodies for
this sort of request -- perhaps it's throwing out the response that
would tell you what's wrong?
Well, the interesting thing is that when I have other errors, I DO get
something back.
Here's an example: If I leave out the User-Agent header, I get a Status
<?xml version="1.0" encoding="UTF-8"?><error><text>Your requests are being
throttled by MusicBrainz because the application you are using has not
identified itself. Please update your application, and see
http://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting for more
http://musicbrainz.org/development/mmd</text></error>
So, I'm definitely looking in the right place. If I add the User-Agent
header back in, then again, I get a response status code of 400 Bad
Request, and an empty response body.
Hm, so at least that much is working, unless your library is doing
something in particular with 400 that it isn't with 503.
Post by Joe Martinez
So, I'm not really sure what might be wrong, I guess :( hopefully something
Post by Ian McEwen
in
there helps. One other small thing I notice is that you're giving a
different client in the URL vs. the user-agent, which I'm guessing isn't
intentional.
Actually, it is intentional. From what I saw in the documentation, it
looks like User-Agent refers to the name/version of the client library, and
the client in the URL refers to the end user application.
https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#Submitting_data
"POST requests should always include a 'client' parameter in the URL (not
the body). The value of 'client' should be the ID of the client software
submitting data. This has to be the application's name and version number,
not that of a client library (client libraries should use HTTP's User-Agent
header). The recommended format is "application-version", where version
does not contain a - character."
Did I misinterpret that?
A bit. The user-agent should ideally reflect both the client library and
the end-user application; python-musicbrainzngs, which is typically our
go-to example library for this sort of thing, sets a useragent like
"MyApp/0.1 python-musicbrainzngs/0.5 ( contact info for MyApp )", by way
of a set_useragent function that takes the app name, the version number,
and the contact info (with the library inserting the
python-musicbrainzngs/0.5, or whatever version number, in the middle).
libmusicbrainz, the C library, works similarly.

The client parameter in the URL should identify the end-user
application, however, and generally doesn't include the library. In both
cases the goal is being able to distinguish submitted data that might be
suspect for whatever reason, whether it be bad coding, end-user misuse,
etc. Since bugs and misbehavior can originate in both a library and in
software using the library, we'd like to know about both!
Post by Joe Martinez
Post by Ian McEwen
Hope you find out what's wrong!
Me too! I don't suppose there's a way I could send the response to a test
server that someone can look at and tell me what they see wrong on the
server side?
Presumably if you wanted to you could set up such a server yourself, but
that may not correspond to your investment in the problem! I suspect
that debugging this will require adding some debugging code (probably
just printlining) into the server itself as well -- the fact it's
failing without an error message suggests to me that it may be failing
somewhere that isn't in our part of the code but rather in the web
framework, but I'm not sure.

If you're interested in trying to test it yourself, you'll need something
running linux, and the codebase is at
https://bitbucket.org/metabrainz/musicbrainz-server/

If you're not:
On which platforms would your code run, and would you be able to send a
piece of test code and compilation instructions/a binary that fails in
this way? Most of the developers are *nix folks (Linux and Mac,
mostly), but I'm sure we could find a suitable Windows machine to test
with if that's how the compatibility falls.

Either way, assuming you come around when we're awake and paying
attention, the less-asynchronous place we work is the IRC channel
#musicbrainz-devel, on Freenode:
https://webchat.freenode.net/?channels=%23musicbrainz-devel will work if
you don't have an IRC client you prefer already. Working in realtime,
someone might be able to set up their sandbox
(http://wiki.musicbrainz.org/Development/Sandbox) for this temporarily,
which could be the best of both worlds.
Post by Joe Martinez
Thanks,
Joe
P.S. given the possibility it's failing in the web framework, maybe
check character encodings? Windows at least tends to consider UTF-16
primary, which might suggest the presence of byte order marks. It's a
bit of a stretch, but...
Post by Joe Martinez
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Ulrich Klauer
2015-02-15 05:56:56 UTC
Permalink
Post by Ian McEwen
It's somewhat misleading -- the site only lets people set multiples of
20 (i.e., 1-5 "stars"), but on the backend it's 1-100.
0 and 100, even. :-) Though the /ws/1/rating endpoint takes 0 to 5
and multiplies by 20; for full detail WS/2 is required.

Ulrich
Joe Martinez
2015-02-16 06:03:02 UTC
Permalink
Post by Ian McEwen
Post by Joe Martinez
Ian,
Thanks for the response. See my responses below...
On Sat, Feb 14, 2015 at 7:47 PM, Ian McEwen <
Post by Ian McEwen
I'm looking now.
The only thing that stands out to me is that ratings are numbers
between 0 and 100. I'm assuming you meant four stars, which would be
80,
Post by Joe Martinez
Post by Ian McEwen
not 4.
Yes, I was doing it based on a 0-5 rating. I did that based on this
https://musicbrainz.org/doc/Rating_System
Do you know why it says 0-5, when it's really 0-100? Or, is that page
talking about something altogether different?
It's somewhat misleading -- the site only lets people set multiples of
20 (i.e., 1-5 "stars"), but on the backend it's 1-100.
https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#ratings
is fairly sparse but as you can see the example uses 20, which is
clearly not 1-5.
Strangely, now that I have stored a rating, when I read it back using the
XML web service (using ?inc=user-ratings), it sends me back a 1-5 rating.
So, if I send 80, then query it back, it comes back to me as 4. Doesn't
seem very consistent. So, I guess I have to do the scaling back and forth
in code on my end?

-Joe
Ian McEwen
2015-02-16 06:19:53 UTC
Permalink
Post by Joe Martinez
Post by Ian McEwen
Post by Joe Martinez
Ian,
Thanks for the response. See my responses below...
On Sat, Feb 14, 2015 at 7:47 PM, Ian McEwen <
Post by Ian McEwen
I'm looking now.
The only thing that stands out to me is that ratings are numbers
between 0 and 100. I'm assuming you meant four stars, which would be
80,
Post by Joe Martinez
Post by Ian McEwen
not 4.
Yes, I was doing it based on a 0-5 rating. I did that based on this
https://musicbrainz.org/doc/Rating_System
Do you know why it says 0-5, when it's really 0-100? Or, is that page
talking about something altogether different?
It's somewhat misleading -- the site only lets people set multiples of
20 (i.e., 1-5 "stars"), but on the backend it's 1-100.
https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2#ratings
is fairly sparse but as you can see the example uses 20, which is
clearly not 1-5.
Strangely, now that I have stored a rating, when I read it back using the
XML web service (using ?inc=user-ratings), it sends me back a 1-5 rating.
So, if I send 80, then query it back, it comes back to me as 4. Doesn't
seem very consistent. So, I guess I have to do the scaling back and forth
in code on my end?
That seems to be the case. Argh :(

The inc=user-ratings can apparently return decimal values as well, e.g.
if I pass '5' to /ws/2/rating when rating, it'll return 0.25 with
inc=user-ratings.
Post by Joe Martinez
-Joe
_______________________________________________
MusicBrainz-devel mailing list
http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
Loading...