2017-05-17 2 views
0

私はetrade apiと通信するためにpython2.7とrauthを使用するアプリケーションを持っています。Python rauth - POSTリクエストは機能しますか?

イー・トレード検証トークンを取得し、許可セッションが正常に機能を設定し、私が正常にGETを実行することができますが、このようにアクセスします:

url = 'https://etwssandbox.etrade.com/accounts/sandbox/rest/accountlist.json' 
response = session.get(url, params = {'format': 'json'}, header_auth=True) 

は、私は多くにもかかわらず、POSTで任意の成功は全くアクセスしていた、としていません検索は、暴力団の投稿の使用を示す例をまだ見つけていない。

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) 

を、私はイー・トレードから得る応答は次のとおりです:私はしようとしています

{ 
    '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':[ 

    ] 
} 

私はPOSTリクエストと間違って何かをやっていると仮定していますが、それが可能であることrauthライブラリーPOSTリクエストに認証情報を追加していませんか?

答えて

0

まあ、私は失敗したrauth POST要求の一番下には達しませんでしたが、代わりの解決策が見つかりました。

私はイー・トレードの検証ページにログイン情報を挿入/こすりしようとしていた破片& pyvirtualdisplayコードを取り除かれ、その代わりに置き換え例外を除いて、etradePythonApi(https://github.com/haualan/etradePythonAPI/blob/master/etradepy.py)からイー・トレードアクセス機能を使用していますGetting an oauth request token from etrade in Python

すべてのことが、ラストラッパーを経由するのではなく、直接要求を使用してうまく機能しています。これは、POST要求がOauthの祝福を怒っていないことを確認しているようです。

アップデート:私はhttps://github.com/geekbrit/EtradeHotKeys

に適応&を使用して他の人のための私のプログラムが利用可能になりました
関連する問題