I have an application that uses python2.7 and rauth to communicate with the etrade api.
Getting the etrade verification token and setting up an authorized session works, and I can successfully execute GET accesses like this:
url = 'https://etwssandbox.etrade.com/accounts/sandbox/rest/accountlist.json'
response = session.get(url, params = {'format': 'json'}, header_auth=True)
I haven't had any success with POST accesses at all, and despite much searching have yet to find an example that shows the use of post with rauth. I am trying:
url = 'https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder'
id = datetime.datetime.now().strftime('%y%m%d%H%M')+ticker
payload = {
"PlaceEquityOrder": {
"-xmlns": "http://order.etws.etrade.com",
"EquityOrderRequest": {
"accountId": account,
"clientOrderId": id,
"limitPrice": "",
"quantity": qty,
"symbol": ticker,
"orderAction": "BUY",
"priceType": "MARKET",
"marketSession": "REGULAR",
"orderTerm": "GOOD_FOR_DAY"
}
}
}
response = session.post(url, payload, header_auth=True)
and the response I get from etrade is:
{
'cookies':<RequestsCookieJar [
] >,
'_content':'<Error>\n <message>oauth_problem=signature_invalid</message>\n</Error>',
'headers':{
'Content-Length':'69',
'Expires':'Sat, 21 May 1995 12:00:00 GMT',
'Keep-Alive':'timeout=60, max=400',
'apiServerName':'20w44m3',
'Connection':'Keep-Alive',
'Pragma':'no-cache',
'Cache-Control':'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
'Date':'Wed, 17 May 2017 15:16:42 GMT',
'Server':'Apache',
'WWW-Authenticate':'OAuth realm=https://etws.etrade.com/,oauth_problem=signature_invalid'
},
'url': u'https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder',
'status_code':401,
'_content_consumed':True,
'encoding':None,
'request':<PreparedRequest [
POST
] >,
'connection':<requests.adapters.HTTPAdapter object at 0x7f3187f71790>,
'elapsed':datetime.timedelta(0,
0,
149246 ),
'raw':<requests.packages.urllib3.response.HTTPResponse object at 0x7f3186c7ab90>,
'reason':'Unauthorized',
'history':[
]
}
I'm assuming I'm doing something wrong with the POST request, but is it possible that the rauth library isn't adding the authentication stuff to POST requests?