mmohades / Venmo

Venmo API client for Python
GNU General Public License v3.0
145 stars 43 forks source link

Getting error when trying to use Client.log_out #20

Closed ExpertSeahorse closed 3 years ago

ExpertSeahorse commented 3 years ago

The following is my traceback:

Traceback (most recent call last):
  File "Venmo.py", line 100, in <module>
    logout()
  File "Venmo.py", line 97, in logout
    venmo.log_out(access_token)
  File "/home/david/.local/lib/python3.8/site-packages/venmo_api/venmo.py", line 49, in log_out
    return AuthenticationApi.log_out(access_token=access_token)
  File "/home/david/.local/lib/python3.8/site-packages/venmo_api/apis/auth_api.py", line 56, in log_out
    api_client.call_api(resource_path=resource_path,
  File "/home/david/.local/lib/python3.8/site-packages/venmo_api/utils/api_client.py", line 58, in call_api
    return self.__call_api(resource_path=resource_path, method=method,
  File "/home/david/.local/lib/python3.8/site-packages/venmo_api/utils/api_client.py", line 103, in __call_api
    processed_response = self.request(method, url, session,
  File "/home/david/.local/lib/python3.8/site-packages/venmo_api/utils/api_client.py", line 139, in request
    validated_response = self.__validate_response(response, ok_error_codes=ok_error_codes)
  File "/home/david/.local/lib/python3.8/site-packages/venmo_api/utils/api_client.py", line 152, in __validate_response
    body = response.json()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
mmohades commented 3 years ago

An error in log_out often means that either your token isn't valid, or it has been revoked. Try creating a Client with your token again and do something with it, see if it still works?

ExpertSeahorse commented 3 years ago

I created a new token, created a $0.01 charge to someone, then ran Client.log_out().

Same traceback error.

mmohades commented 3 years ago

Is this how you are logging out? Client.log_out(token)? You need to pass your token as the argument to the function. If it's, then try the following, it'll show you the error if there's one:

import requests

token = "Bearer ......"   #  this should be your access token

def revoke_token(token):
    header = {
        "Authorization": token,
        "User-Agent": "Venmo/8.6.1 (iPhone; iOS 13.0; Scale/3.0)"
    }
    url = "https://api.venmo.com/v1/oauth/access_token"
    response = requests.delete(url, headers=header)
    if response.status_code != 200:
        print("ERROR:")
        print(response.status_code, response.reason, response.text)
        return 0

    json = response.json()
    print("Successfully logged out:\n", json)

revoke_token(token)

FYI, you don't have to log in and log_out every time. You can log in once, and keep using your access token as long as you want. Just make sure to keep your token somewhere secure, and remember that it never gets expired, so you'll have to revoke it at some point.

ExpertSeahorse commented 3 years ago

My access token is just in the format "sdaf456sadf", without 'Bearer' (or my username?) at the beginning. Does this change anything?

mmohades commented 3 years ago

Yes, that's probably why it's failing. It should be Bearer sdaf45fgfgdx.... That's a good point tho. I'll update it later on to also accept sdaf456sadf since Client itself accepts both formats.

mmohades commented 3 years ago

Feel free to comment here if you're still having issues with log_out