2013-04-26 25 views
0

我很難與Rauth庫進行的更改,我想任何人都可以幫助。Rauth庫變化 - Python

首先我創建了一個Rauth包裝本身(這僅僅是一個例子,不是我的實際代碼):

service = OAuth2Service(
      name='example', 
      client_id='123', 
      client_secret='456', 
      access_token_url='https://example.com/token', 
      authorize_url='https://example.com/authorize', 
      base_url='https://example.com/api/') 

我那麼做正確的授權書,並返回一個標記,然後我使用的access_token來開會。訪問令牌存在,我檢查。

session = service.get_session(token['access_token']) 

問題是,當我開始查詢時,我發現我的會話無效。

self.session.get(some url, params = self.params, timeout = 30.0).content)

self.params = {'Authorization': 'Bearer ' + self.access_token} 

我不知道如果我使用的圖書館權利有了新的變化。有任何想法嗎?我也不知道如何檢查一個會話是否有效,這樣也可以提供幫助。

+0

請給我們完整的追溯。 – maxcountryman 2013-04-26 02:38:11

+0

我修復了一部分。現在我的主要問題是,它返回類似於: {「totalSize」:1,「done」:true,「records」:[{「attributes」:{「type」:「My_Pets__c」,「url」:「 /services/data/v20.0/sobjects/My_Pets__c/*********"},"Id":"*********「}]} 我正在嘗試以正常的方式訪問它,你會訪問一個字典,結果['記錄'],我得到這樣的錯誤: TypeError:字符串索引必須是整數,而不是str。 當我嘗試將它轉換爲JSON來訪問它時,我得到 AttributeError:'str'對象沒有屬性'json' – CoffeeIsProgramming 2013-04-26 02:47:54

+0

這是因爲它返回一個JSON字符串。試試這個:'data = session.get(...).json()'。 – maxcountryman 2013-04-26 02:49:05

回答