alexander-pick / MKMTool

MKMTool ist a helper application I wrote for tinkering around with optimization of sale processes on magiccardmarket.eu and the idea of automisation of some tasks most people wouldn’t be able to get done by pure manpower.
GNU Affero General Public License v3.0
65 stars 15 forks source link

mkmtool doesnt update prices #38

Closed pepev12 closed 3 years ago

pepev12 commented 3 years ago

Hi all and thanks for your amazing work with this tool,

I'm having a problem updating prices, the prices are calculated ok, but every 100 lines i see this in the log:

Error with sending stock update to MKM: Los bytes que se van a escribir en la secuencia sobrepasan el tamaño de bytes especificado en el valor Content-Length.

which is spanish for: Bytes to be written to the stream exceed the Content-Length bytes size specified

I have updated prices before without issue, why is this? something about mkm not allowing me using the api? im in my daily limit,

thanks!

pepev12 commented 3 years ago

Im also having this error: Error with sending stock update to MKM: Anulada la solicitud: La solicitud fue cancelada. But it doesnt always happens, sometimes the tool update the batch just fine, So i understand this is something in mkm side, timeouts or other problems, maybe a setting for trying again when update fails may be usefull? regards,

pepev12 commented 3 years ago

an update about this, i finally figure out what was happening, the error was because some invalid characters in the comment section of the card,,, when the tool tried to update prices, mkm read the comment with an invalid character (although it was already there) and cancel the call, i made a cleanup of invalid characters and now its working perfectly, regards,

tomasjanak commented 3 years ago

do you remember what were the invalid characters so that I could add some checks for that to avoid crashes?

pepev12 commented 3 years ago

mmm im not sure, weird unicode codes, i have an inventory export before changing them and in the csv they look like this: â ¢ But that's not what they looked like in mkm; At least one of them was like a black circle in the middle of the character space, but i have no idea how to type it,

tomasjanak commented 3 years ago

I can recreate the problem using these characters inside comments, but I don't know how to fix it, somebody with more knowledge on .NET and it's XML libraries is needed.

alexander-pick commented 3 years ago

That seems to be due to the unicode encoding of the char which takes 2 bytes instead of one and might be a bug in the library which creates the request or a wrong length param calculated.

alexander-pick commented 3 years ago

Take a look at this line (83) in MKMInteract.cs:

request.ContentLength = body.Length;

This counts chars, not bytes. I think changing this to something like the line blow might fix it:

request.ContentLength = Encoding.Unicode.GetByteCount(body);

I haven't tested it, but this is the classic issue in this case.

tomasjanak commented 3 years ago

Thanks, Encoding.UTF8.GetByteCount(body); works.

(I'll push the code in later with other changes & fixes, hopefully by end of the week)

tomasjanak commented 3 years ago

Fixed in commit https://github.com/alexander-pick/MKMTool/commit/e024575c9efe25942e8530212d2d634fbc1e274d (available in version 0.8.0.0 or newer)