joalla / discogs_client

Continuation of the "Official Python Client for the Discogs API"
https://python3-discogs-client.readthedocs.io
Other
309 stars 50 forks source link

Error 400 still occurring on some configurations #29

Closed hellricer closed 3 years ago

hellricer commented 3 years ago

There are apparently still issues with error 400 on post requests since #18. Seems to happen only on some setups for some reason - might be related to different versions of dependencies?

Python 3.8.3 & 3.9.1 requests 2.25.1 oauthlib 3.1.0

Test code:

import discogs_client
ds = discogs_client.Client('DevApp/1.0', user_token='...')
me = ds.identity()
me.wantlist.add(89411)
AnssiAhola commented 3 years ago

Okay, I think I found the issue. When using the user_token it uses UserTokenRequestsFetcher, which does not convert the data to json string. https://github.com/joalla/discogs_client/blob/9d1292a83f9ef5dbeda386f2b2eaf1f3a1346dff/discogs_client/fetchers.py#L55-L63 I changed the fetch method to match the oauth one like so

def fetch(self, client, method, url, data=None, headers=None, json_format=True):
        data = json.dumps(data) if json_format and data else data
        resp = requests.request(method, url, params={'token':self.user_token},
                                data=data, headers=headers)
       ...

Hope this is the only culprit

~Maybe this method should be implemented in the base Fetcher class?~ Nvm each class implements it differently 🤦

~Good solution to this could be implementing the method properly in RequestsFetcher class and inheriting it in OAuth2Fetcher and UserTokenRequestsFetcher (I know, annoying mismatched naming, lol)~ Arghh, thinking too fast without inspecting the code properly

hellricer commented 3 years ago

Great find, thanks. Would you mind creating the PR, or do you want to include it in #27?

AnssiAhola commented 3 years ago

I'll create a new PR, as it's not really related to changes made in #27

alifhughes commented 3 years ago

@AnssiAhola @hellricer PR was merged and package with change has been released - version 2.3.8. I'm going to close this issue but feel free to open it again if the problem arises. Thanks for the quick work guys.