2015-03-13 24 views
0

我試圖在類似的django項目中實現mailchimp python API,他們的示例在github上。我試圖讓基於類視圖連接然而,當我打開了我得到Mailchimp python包裝給出錯誤 - 沒有會話

Attribute Error at\ 'module' object has no attribute 'session'

它的設置完全一樣的例子通知視圖和發生錯誤的位置,我定義

m = get_mailchimp_api()

我在我的網站包裝開闢了mailchimp.py文件下列回溯後,看到以下內容:

import requests 

class Mailchimp(object): 
    root = 'https://api.mailchimp.com/2.0/' 
    def __init__(self, apikey=None, debug=False): 
     '''Initialize the API client 

     Args: 
      apikey (str|None): provide your MailChimp API key. If this is left as None, we will attempt to get the API key from the following locations:: 
       - MAILCHIMP_APIKEY in the environment vars 
       - ~/.mailchimp.key for the user executing the script 
       - /etc/mailchimp.key 
      debug (bool): set to True to log all the request and response information to the "mailchimp" logger at the INFO level. When set to false, it will log at the DEBUG level. By default it will write log entries to STDERR 
     ''' 

     self.session = requests.session() 

回溯結束於self.session = requests.session()行。

這是我的看法,我正在嘗試撥打Mailchimp

from app.utils import get_mailchimp_api 
import mailchimp 
from django.views.generic import TemplateView 

class HomeView(TemplateView): 
    template_name = 'home.html' 
    # print requests -- this is undefined 
    m = get_mailchimp_api() 

是不是因爲CBV沒有請求參數?在github的例子中,它們顯示了連接是在函數接受請求的基於函數的視圖中進行的。如果是這樣的話,我怎麼能把答案傳遞給CBV?這是確切的例子Mailchimp給出了GitHub上:

def index(request): 
    try: 
     m = get_mailchimp_api() 
     lists = m.lists.list() 
    except mailchimp.Error, e: 
     messages.error(request, 'An error occurred: %s - %s' % (e.__class__, e)) 
     return redirect('/') 

回答

0

Requests沒有session()方法...但ID 確實Session()對象。

聽起來像包裝中的錯誤。

0

請求別名Session() with session(),所以這可能不是問題。這幾乎聽起來像你的get_mailchimp_api()方法有東西或東西與進口奇怪。其他有關類似錯誤消息的stackoverflow問題似乎來自互相輸入,拼寫錯誤或其他類似的東西。

推測你的app.utils模塊已經導入mailchimp了,like MailChimp's does?如果沒有,我會嘗試。如果是這樣,也許從這個文件中刪除您的import mailchimp

相關問題