mailjet / mailjet-apiv3-python

[API v3] Python Mailjet wrapper

Home Page:https://dev.mailjet.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mailjet.statistics_recipient-esp.get NameError

opened this issue · comments

Code snippet from https://dev.mailjet.com/email/guides/statistics/#mailbox-provider-statistics produces: Exception has occurred: NameError name 'esp' is not defined for both 2.7 and 3.7 versions.

Was told that it is issue with wrapper and I should post new issue here.

I had an issue with using mailjet_rest for python where hyphen was used in attribute name like here: https://dev.mailjet.com/email/guides/statistics/#key-performance-statistics
EXAMPLE
import os
api_key = os.environ['MJ_APIKEY_PUBLIC']
api_secret = os.environ['MJ_APIKEY_PRIVATE']
mailjet = Client(auth=(api_key, api_secret))
filters = { 'CampaignId': '$Campaign_ID' }
result = mailjet.statistics_recipient-esp.get(filters=filters)
print result.status_code print result.json()

MY CODE and ERROR >>>
filters = {'CampaignId': mj_deployment_id}
mailjet.statistics_recipient-esp.get(filters=filters).json()

Traceback (most recent call last): File "/usr/lib/python3.6/code.py", line 91, in runcode exec(code, self.locals) File "", line 1, in NameError: name 'esp' is not defined

WORKAROUND for my case only
mailjet_rest.client.py
class Client(object):
def __init__(self, auth=None, **kwargs):
self.auth = auth
version = kwargs.get('version', None)
api_url = kwargs.get('api_url', None)
self.config = Config(version=version, api_url=api_url)
def __getattr__(self, name):
if name == 'statistics_recipient':
name = 'statistics_recipient-esp'
#split = ['statistics', 'recipient-esp'] .....

The issue was due to we can not use hyphen in python methods attribute. Maybe I am using this python API in not correct way) but I didn't found tips on your site or some google advises how to maybe more properly use this official python wrapper https://github.com/mailjet/mailjet-apiv3-python

Could you try to use getattr?

For example:

getattr(mailjet, 'statistics_recipient-esp').get(filters=filters)

We were decided to use getattr solution here as mentioned in the previous comment. This will be also updated in official documentation soon.