evonove / mkm-sdk

33 stars 14 forks source link

Spaces (and maybe other special characters) in the request URL yield a 401: Unauthorized #6

Closed pfirsich closed 8 years ago

pfirsich commented 8 years ago

I am not 100% sure, but I tested with a handful of different cards and it seems that market_place.products only does not give an error, when the name does not contain a space (or a comma).

Cards like Endbringer, Dispel work flawlessly with market_place.products, but "Lightning Bolt", "Endless One" and "Jace, the Mind Sculptor" do not. Requests does automatically escape URLs, so that it will fetch the url with escapes spaces, but the MKMOAuth1-class does have an incorret realm-field then. One fix would be to pass an already escaped url. This will work:

mkm.market_place.products(name = "Lightning%20Bolt", game = 1, language = 3, match = False)

Also Requests (for some reason) does not escape comma (and maybe more), so that

mkm.market_place.products(name = "Jace, the Mind Sculptor", game = 1, language = 3, match = False)

fetches:

https://www.mkmapi.eu/ws/v1.1/output.json/products/Jace,%20the%20Mind%20Sculptor/1/3/false

while it should fetch:

/products/Jace%2C%20the%20Mind%20Sculptor/1/3/false

It seems as though mkm-sdk would have to url encode some fields itself. If this is intended, then mkm-sdk should at least document this, because finding all this out took me quite and I don't seem many reasons to not auto-escape the fields itself.

silvanocerza commented 8 years ago

This is not intended. I'll release the fix with the next version, I don't think it will take that much time. Thank you for reporting this.