为什么我只能用这个python代码发出GET请求而不是POST请求?

时间:2017-09-02 21:45:37

标签: python oauth rauth

我正试图让这个Etrade的东西运行起来....到目前为止我有:

from rauth import OAuth1Service
import webbrowser 

def getSession():
    # Create a session
    # Use actual consumer secret and key in place of 'foo' and 'bar'
    service = OAuth1Service(
              name = 'etrade',
              consumer_key = 'cabf024eaXXXXXXXXX7a0243d8d',  
              consumer_secret = '3d05c41XXXXXXXXX1949d07c',
              request_token_url = 
'https://etws.etrade.com/oauth/request_token',
              access_token_url = 
'https://etws.etrade.com/oauth/access_token',
              authorize_url = 'https://us.etrade.com/e/t/etws/authorize?
key={}&token={}',
              base_url = 'https://etws.etrade.com')

    # Get request token and secret    
    oauth_token, oauth_token_secret = service.get_request_token(params = 
                              {'oauth_callback': 'oob', 
                               'format': 'json'})

    auth_url = service.authorize_url.format('cabf0XXXXXXXXXa0243d8d', 
oauth_token)

    webbrowser.open(auth_url)
    verifier = raw_input('Please input the verifier: ')

    return service.get_auth_session(oauth_token, oauth_token_secret, 
params = {'oauth_verifier': verifier})  

session = getSession()

此身份验证过程完全正常,并且允许我执行获取/删除请求,但是当我尝试发布请求时:

url = 
'https://etwssandbox.etrade.com/order/sandbox/rest/previewoptionorder'
para = {
    "PreviewOptionOrder": {
     "-xmlns": "http://order.etws.etrade.com",
     "OptionOrderRequest": {
       "accountId": "83550325",
       "quantity": "4",
       "symbolInfo": {
         "symbol": "AAPL",
         "callOrPut": "CALL",
         "strikePrice": "585",
         "expirationYear": "2012",
         "expirationMonth": "07",
         "expirationDay": "21"
       }, 
       "orderAction": "BUY_OPEN",

                           "priceType": "MARKET",
       "orderTerm": "GOOD_FOR_DAY"
     }
   }  
 }
resp = session.post(url,data=para)
resp.text

我收到错误:

Unauthorized request: consumer key is missing.

我尝试了很多东西(授予我这个东西的新手)。我尝试使用只是请求进行身份验证无效,我尝试将oauth1对象作为kw参数传递给posts函数。有什么想法吗?

0 个答案:

没有答案