Python 值错误位于/admin/marketing/marketingpreference/add/,太多值无法解压缩(预期为2个)
我正在尝试在营销应用程序中创建我的用户模型电子邮件。我在看视频中的营销应用程序教程。但在那个视频中,这个程序并没有显示错误。当我编写同一个程序时,显示错误: 值错误位于/admin/marketing/marketingpreference/add/ 要解压缩的值太多(预期为2) 还有我的utils.pyPython 值错误位于/admin/marketing/marketingpreference/add/,太多值无法解压缩(预期为2个),python,django,python-3.x,django-models,django-rest-framework,Python,Django,Python 3.x,Django Models,Django Rest Framework,我正在尝试在营销应用程序中创建我的用户模型电子邮件。我在看视频中的营销应用程序教程。但在那个视频中,这个程序并没有显示错误。当我编写同一个程序时,显示错误: 值错误位于/admin/marketing/marketingpreference/add/ 要解压缩的值太多(预期为2) 还有我的utils.py class Mailchimp(object): def __init__(self): super(Mailchimp, self).__init__()
class Mailchimp(object):
def __init__(self):
super(Mailchimp, self).__init__()
self.key = MAILCHIMP_API_KEY
self.api_url = "https://{dc}.api.mailchimp.com/3.0".format(dc=MAILCHIMP_DATA_CENTER)
self.list_id = MAILCHIMP_EMAIL_LIST_ID
self.list_endpoint = '{api_url}/lists/{list_id}'.format(api_url=self.api_url, list_id=self.list_id)
def get_member_endpoint(self):
return self.list_endpoint + "/members"
def check_valid_status(self, status):
choices = ['subscribed','unsubscribed','cleaned', 'pending']
if status not in choices:
raise ValueError("Not a valid choice for email status")
return status
def add_email(self, email,status = "subscribed"):
self.check_valid_status(status)
data = {
"email_address": email,
"status": status
}
endpoint = self.get_member_endpoint()
r =requests.post(endpoint, auth=("", self.key), data=json.dumps(data))
return r.json()
def subscribe(self, email):
return self.add_email(email)
我的终端显示了这个
[14/Feb/2020 21:15:38] "GET /admin/jsi18n/ HTTP/1.1" 200 3223
Internal Server Error: /admin/marketing/marketingpreference/add/
Traceback (most recent call last):
"D:\software\shopw\marketing\models.py", line 35, in marketing_pref_update_receiver
status_code, response_data = Mailchimp().unsubscribe(instance.user.email)
ValueError: too many values to unpack (expected 2)
请帮帮我。好吧,您的
Mailchimp.unsubscribe()
方法返回一个对象(r.json()
)。如果该对象不是2元组,那么python无法将其映射到status\u code、response\u data
。看看什么是r.json()
。非常感谢@dirkgroten。我没有写这个r.status_代码,r.json()
[14/Feb/2020 21:15:38] "GET /admin/jsi18n/ HTTP/1.1" 200 3223
Internal Server Error: /admin/marketing/marketingpreference/add/
Traceback (most recent call last):
"D:\software\shopw\marketing\models.py", line 35, in marketing_pref_update_receiver
status_code, response_data = Mailchimp().unsubscribe(instance.user.email)
ValueError: too many values to unpack (expected 2)