jessecooper / pyetrade

Python E-Trade API Wrapper
GNU General Public License v3.0
209 stars 97 forks source link

HTTPError: 401 Client Error: Unauthorized for url #8

Closed kwmkwm closed 5 years ago

kwmkwm commented 5 years ago

Hello,

I'm getting an error while trying to use the list_accounts() function in the sandbox environment. My censored code:

#!/usr/bin/python3
import pyetrade
consumer_key = "REMOVED"
consumer_secret = "REMOVED"
oauth = pyetrade.ETradeOAuth(consumer_key, consumer_secret)
print("checkpoint 1")
print("Visit site and obtain code")
print(oauth.get_request_token())
tokens = oauth.get_access_token(input("Enter Token:  "))
print("checkpoing 2")
print(tokens)
accounts = pyetrade.ETradeAccounts(
        consumer_key,
        consumer_secret,
        tokens['oauth_token'],
        tokens['oauth_token_secret']
    )
print("checkpoint 3")
accounts.list_accounts()
print("checkpoint 4")

All seems well until the accounts.list_accounts() function. The censored output:

checkpoint 1
Visit site and obtain code
https://us.etrade.com/e/t/etws/authorize?key=REMOVED
Enter Token:  REMOVED
checkpoing 2
{'oauth_token_secret': 'REMOVED', 'oauth_token': 'REMOVED'}
checkpoint 3
Traceback (most recent call last):
  File "./etrade-test.py", line 22, in <module>
    accounts.list_accounts()
  File "/usr/local/lib/python3.5/dist-packages/pyetrade/accounts.py", line 54, in list_accounts
    req.raise_for_status()
  File "/home/REMOVED/.local/lib/python3.5/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://etwssandbox.etrade.com/accounts/sandbox/rest/accountlist.json

uname -a Linux THX-1138 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux

hwclock --debug hwclock from util-linux 2.29.2 Using the /dev interface to the clock. Last drift adjustment done at 1543475777 seconds after 1969 Last calibration done at 1543475777 seconds after 1969 Hardware clock is on UTC time Assuming hardware clock is kept in UTC time.

Any suggestions on this issue?

jessecooper commented 5 years ago

Do you have an APIv1 token or APIv0. Current master branch and version on PyPI are all for version v0 but etrade is currently going to APIv1. Each of these versions has a different consumer token that you have to get form etrade. If you want to use APIv1 the dev branch is currently being migrated over to APIv1 but functionality is limited at this time.

kwmkwm commented 5 years ago

I tried the dev branch and the code worked as expected. I think this resolves the issue, so I will close it. Thank you.