After following the documentation, I made it to this point:
contact_list = mailjet_api.lists.create(
label='test',
name='Test list',
method='POST'
)
But instead of:
{
'status': 'OK',
'contact_id': 000000000
}
This is what it looks like:
In [1]: import mailjet
In [2]: mailjet_api = mailjet.Api()
In [3]: account_info = mailjet_api.user.infos()
In [4]: account_info
Out[4]:
{u'infos': {u'address_city': u'Paris',
u'address_country': u'FR',
u'address_postal_code': u'75999',
u'address_street': u'7 rue oeuoeuaoeu',
u'company_name': u'',
u'contact_phone': u'0123456789',
u'currency': u'EUR',
u'email': u'[email protected]',
u'firstname': u'James',
u'lastname': u'Pic',
u'locale': u'en_EU',
u'timezone': u'Europe/Paris',
u'tracking_clicks': u'1',
u'tracking_openers': u'1',
u'username': u'[email protected]'},
u'status': u'OK'}
In [5]: contact_list = mailjet_api.lists.create(
label='test5',
name='Test list 5',
method='POST'
)
/home/jpic/jousse/jousse_env/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:53: RuntimeWarning: SQLite received a naive datetime (2013-09-10 17:22:15.227605) while time zone support is active.
RuntimeWarning)
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
/home/jpic/jousse/jousse_env/local/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
2 label='test5',
3 name='Test list 5',
----> 4 method='POST'
5 )
/home/jpic/jousse/jousse_env/local/lib/python2.7/site-packages/mailjet/api.py in __call__(self, **kwargs)
40 self.function,
41 options=options,
---> 42 postdata=postdata,
43 )
44 return json.load(response)
/home/jpic/jousse/jousse_env/local/lib/python2.7/site-packages/mailjet/connection.pyc in open(self, method, function, options, postdata)
48
49 opener = self.get_opener(url)
---> 50 return opener.open(url, poststring, self.timeout)
51
52 @classmethod
/usr/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout)
408 for processor in self.process_response.get(protocol, []):
409 meth = getattr(processor, meth_name)
--> 410 response = meth(req, response)
411
412 return response
/usr/lib/python2.7/urllib2.pyc in http_response(self, request, response)
521 if not (200 <= code < 300):
522 response = self.parent.error(
--> 523 'http', request, response, code, msg, hdrs)
524
525 return response
/usr/lib/python2.7/urllib2.pyc in error(self, proto, *args)
440 http_err = 0
441 args = (dict, proto, meth_name) + args
--> 442 result = self._call_chain(*args)
443 if result:
444 return result
/usr/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, *args)
380 func = getattr(handler, meth_name)
381
--> 382 result = func(*args)
383 if result is not None:
384 return result
/usr/lib/python2.7/urllib2.pyc in http_error_401(self, req, fp, code, msg, headers)
895 url = req.get_full_url()
896 response = self.http_error_auth_reqed('www-authenticate',
--> 897 url, req, headers)
898 self.reset_retry_count()
899 return response
/usr/lib/python2.7/urllib2.pyc in http_error_auth_reqed(self, authreq, host, req, headers)
870 UserWarning, 2)
871 if scheme.lower() == 'basic':
--> 872 response = self.retry_http_basic_auth(host, req, realm)
873 if response and response.code != 401:
874 self.retried = 0
/usr/lib/python2.7/urllib2.pyc in retry_http_basic_auth(self, host, req, realm)
883 return None
884 req.add_unredirected_header(self.auth_header, auth)
--> 885 return self.parent.open(req, timeout=req.timeout)
886 else:
887 return None
/usr/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout)
408 for processor in self.process_response.get(protocol, []):
409 meth = getattr(processor, meth_name)
--> 410 response = meth(req, response)
411
412 return response
/usr/lib/python2.7/urllib2.pyc in http_response(self, request, response)
521 if not (200 <= code < 300):
522 response = self.parent.error(
--> 523 'http', request, response, code, msg, hdrs)
524
525 return response
/usr/lib/python2.7/urllib2.pyc in error(self, proto, *args)
446 if http_err:
447 args = (dict, 'default', 'http_error_default') + orig_args
--> 448 return self._call_chain(*args)
449
450 # XXX probably also want an abstract factory that knows when it makes
/usr/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, *args)
380 func = getattr(handler, meth_name)
381
--> 382 result = func(*args)
383 if result is not None:
384 return result
/usr/lib/python2.7/urllib2.pyc in http_error_default(self, req, fp, code, msg, hdrs)
529 class HTTPDefaultErrorHandler(BaseHandler):
530 def http_error_default(self, req, fp, code, msg, hdrs):
--> 531 raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
532
533 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 400: Bad Request
At first I thought it was a problem with capitalisation, but I tried with Create and it doesn't work either (note: I added some print statements to make it easier to debug):
In [8]: contact_list = mailjet_api.lists.Create(
label='test5',
name='Test list 5',
method='POST'
)
<mailjet.api.ApiMethod object at 0x9bb466c> Create None {'name': 'Test list 5', 'label': 'test5'}
<urllib2.OpenerDirector instance at 0x9ba9c6c> https://api.mailjet.com/0.1/listsCreate?output=json name=Test+list+5&label=test5
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
/home/jpic/jousse/jousse_env/local/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
2 label='test5',
3 name='Test list 5',
----> 4 method='POST'
5 )
/home/jpic/jousse/jousse_env/local/lib/python2.7/site-packages/mailjet/api.pyc in __call__(self, **kwargs)
41 self.function,
42 options=options,
---> 43 postdata=postdata,
44 )
45 return json.load(response)
/home/jpic/jousse/jousse_env/local/lib/python2.7/site-packages/mailjet/connection.py in open(self, method, function, options, postdata)
49 opener = self.get_opener(url)
50 print opener, url, poststring
---> 51 return opener.open(url, poststring, self.timeout)
52
53 @classmethod
/usr/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout)
408 for processor in self.process_response.get(protocol, []):
409 meth = getattr(processor, meth_name)
--> 410 response = meth(req, response)
411
412 return response
/usr/lib/python2.7/urllib2.pyc in http_response(self, request, response)
521 if not (200 <= code < 300):
522 response = self.parent.error(
--> 523 'http', request, response, code, msg, hdrs)
524
525 return response
/usr/lib/python2.7/urllib2.pyc in error(self, proto, *args)
440 http_err = 0
441 args = (dict, proto, meth_name) + args
--> 442 result = self._call_chain(*args)
443 if result:
444 return result
/usr/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, *args)
380 func = getattr(handler, meth_name)
381
--> 382 result = func(*args)
383 if result is not None:
384 return result
/usr/lib/python2.7/urllib2.pyc in http_error_401(self, req, fp, code, msg, headers)
895 url = req.get_full_url()
896 response = self.http_error_auth_reqed('www-authenticate',
--> 897 url, req, headers)
898 self.reset_retry_count()
899 return response
/usr/lib/python2.7/urllib2.pyc in http_error_auth_reqed(self, authreq, host, req, headers)
870 UserWarning, 2)
871 if scheme.lower() == 'basic':
--> 872 response = self.retry_http_basic_auth(host, req, realm)
873 if response and response.code != 401:
874 self.retried = 0
/usr/lib/python2.7/urllib2.pyc in retry_http_basic_auth(self, host, req, realm)
883 return None
884 req.add_unredirected_header(self.auth_header, auth)
--> 885 return self.parent.open(req, timeout=req.timeout)
886 else:
887 return None
/usr/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout)
408 for processor in self.process_response.get(protocol, []):
409 meth = getattr(processor, meth_name)
--> 410 response = meth(req, response)
411
412 return response
/usr/lib/python2.7/urllib2.pyc in http_response(self, request, response)
521 if not (200 <= code < 300):
522 response = self.parent.error(
--> 523 'http', request, response, code, msg, hdrs)
524
525 return response
/usr/lib/python2.7/urllib2.pyc in error(self, proto, *args)
446 if http_err:
447 args = (dict, 'default', 'http_error_default') + orig_args
--> 448 return self._call_chain(*args)
449
450 # XXX probably also want an abstract factory that knows when it makes
/usr/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, *args)
380 func = getattr(handler, meth_name)
381
--> 382 result = func(*args)
383 if result is not None:
384 return result
/usr/lib/python2.7/urllib2.pyc in http_error_default(self, req, fp, code, msg, hdrs)
529 class HTTPDefaultErrorHandler(BaseHandler):
530 def http_error_default(self, req, fp, code, msg, hdrs):
--> 531 raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
532
533 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 400: Bad Request