charliewolf / pynder

:fire: Python client for tinder api
Other
638 stars 142 forks source link

pynder.errors.RequestError: 400 #193

Open jasonminsookim opened 6 years ago

jasonminsookim commented 6 years ago

Here's the code I used:

`session = pynder.Session(facebook_id=myId, facebook_token=myToken)

list(session.matches())`

Here's the error I got: Traceback (most recent call last): File "/Users/jasonkim/PycharmProjects/JynderBot/brainstorming.py", line 8, in list(session.matches()) File "/Users/jasonkim/PycharmProjects/JynderBot/venv/lib/python3.5/site-packages/pynder/session.py", line 48, in return (Match(match, self) for match in response if 'person' in match) File "/Users/jasonkim/PycharmProjects/JynderBot/venv/lib/python3.5/site-packages/pynder/models/user.py", line 135, in init match['person']['_id'])['results'] File "/Users/jasonkim/PycharmProjects/JynderBot/venv/lib/python3.5/site-packages/pynder/api.py", line 120, in user_info return self._get("/user/" + user_id) File "/Users/jasonkim/PycharmProjects/JynderBot/venv/lib/python3.5/site-packages/pynder/api.py", line 52, in _get return self._request("get", url) File "/Users/jasonkim/PycharmProjects/JynderBot/venv/lib/python3.5/site-packages/pynder/api.py", line 46, in _request raise errors.RequestError(result.status_code) pynder.errors.RequestError: 400

PaulAhuevo commented 6 years ago

Hi, there are new "users" (advertisement) that cause problems. I put serveral methods into try / except blocks to handle the error.

Change the pynder code in user.py to something like this and it should work:

        if 'person' in match:
            try:
                _id = match['person']['_id']
                user_data = _session._api.user_info(_id)['results']
                user_data['_id'] = _id
                self.user = User(user_data, _session)
                self.messages = [
                    Message(m, user=self.user)
                    for m in match['messages']
                ]
            except Exception as e:
                print("Not normal user: Advertisement / Deleted: " + str(e))
acerock6 commented 4 years ago

The error still persists even after making the code change you suggested.

`RequestError Traceback (most recent call last)

in 2 3 session = pynder.Session(facebook_id, facebook_auth_token) ----> 4 session.profile //anaconda3/lib/python3.7/site-packages/cached_property.py in __get__(self, obj, cls) 33 return self._wrap_in_coroutine(obj) 34 ---> 35 value = obj.__dict__[self.func.__name__] = self.func(obj) 36 return value 37 //anaconda3/lib/python3.7/site-packages/pynder/session.py in profile(self) 20 @cached_property 21 def profile(self): ---> 22 return Profile(self._api.profile(), self._api) 23 24 def nearby_users(self, limit=10): //anaconda3/lib/python3.7/site-packages/pynder/api.py in profile(self) 66 67 def profile(self): ---> 68 return self._get("/profile") 69 70 def update_profile(self, profile): //anaconda3/lib/python3.7/site-packages/pynder/api.py in _get(self, url) 45 46 def _get(self, url): ---> 47 return self._request("get", url) 48 49 def _post(self, url, data={}): //anaconda3/lib/python3.7/site-packages/pynder/api.py in _request(self, method, url, data) 39 url), data=data, proxies=self._proxies) 40 if result.status_code < 200 or result.status_code >= 300: ---> 41 raise errors.RequestError(result.status_code) 42 if result.status_code == 201 or result.status_code == 204: 43 return {} RequestError: 400` Pynder version: 0.0.13