chartmogul / chartmogul-python Goto Github PK
View Code? Open in Web Editor NEWChartMogul API Python Client
License: MIT License
ChartMogul API Python Client
License: MIT License
I've verified that the provided ChartMogul UUID argument is correct, however, I keep getting a 404 response with the message "Customer not found". I've tested with both curl and the Python API.
While retrieving the MRR,
chartmogul.Metrics.mrr(
config,
start_date="2021-12-01",
end_date="2022-06-21",
interval="month")
I'm getting this error message:
<Promise at 0x1622921c0 rejected with ValidationError({0: {'percentage-change': ['Unknown field.']}, 1: {'percentage-change': ['Unknown field.']}, 2: {'percentage-change': ['Unknown field.']}, 3: {'percentage-change': ['Unknown field.']}, 4: {'percentage-change': ['Unknown field.']}, 5: {'percentage-change': ['Unknown field.']}, 6: {'percentage-change': ['Unknown field.']}})>
It looks like in 8cc4c6e this was renamed to chartmogul.CustomerSubscription
but not all the documentation was updated. Under the "Import API" docs it still has the old name. It's also not updated in the README.md under "Subscriptions".
Can you guys please provide a practical example of using promises to use the API asynchronously? It's just super unclear, and nothing I'm trying is working.
I think I've managed to suss out how this works, but the documentation and code needs some updating.
The README.md has this example that seems like a bad copy-paste from merge
:
chartmogul.Customer.modify(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={
'from': {'customer_uuid': 'cus_5915ee5a-babd-406b-b8ce-d207133fb4cb'},
'into': {'customer_uuid': 'cus_2123290f-09c8-4628-a205-db5596bd58f7'}
})
Maybe should be replaced with something like (taken from the API docs):
chartmogul.Customer.modify(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={
"city": "San Francisco",
"country": "US",
"state": "CA",
})
Also, both the Update a Customer docs and code seem to imply you can call modify
without any UUID. I haven't tried it, but I suspect it doesn't work. If it should be required, it seems like modify
(and any of the other patch
actions) should be added here:
chartmogul-python/chartmogul/resource.py
Lines 150 to 154 in 377fa17
data
are required for that to work.
Incidentally, it seems like the library allows a chartmogul.Customer.update
call which does a PUT. I'm not sure if this actually works, but if the API allows it then it seems like a "foot gun" where people will by trying to "Update a Customer" but actually replacing the whole document with just the parts they want to update.
v3.0.0 hasn't been published to pypi
When I try to create an Invoice I get this exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/promise/promise.py", line 65, in try_catch
return (handler(*args, **kwargs), None)
File "/usr/local/lib/python3.6/site-packages/chartmogul/resource.py", line 85, in _load
response.raise_for_status()
File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: https://api.chartmogul.com/v1/import/customers/invoices
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 2, in <module>
File "/Users/sento/dev/test/chartmogul.py", line 66, in create_invoice
return chartmogul.Invoice.create(config, uuid=cus_uuid, data=data).get().uuid
File "/usr/local/lib/python3.6/site-packages/promise/promise.py", line 423, in get
return self._target_settled_value(_raise=True)
File "/usr/local/lib/python3.6/site-packages/promise/promise.py", line 426, in _target_settled_value
return self._target()._settled_value(_raise)
File "/usr/local/lib/python3.6/site-packages/promise/promise.py", line 187, in _settled_value
reraise(type(raise_val), raise_val, self._traceback)
File "/usr/local/lib/python3.6/site-packages/six.py", line 693, in reraise
raise value
File "/usr/local/lib/python3.6/site-packages/promise/promise.py", line 65, in try_catch
return (handler(*args, **kwargs), None)
File "/usr/local/lib/python3.6/site-packages/chartmogul/errors.py", line 19, in annotateHTTPError
raise_from(APIError(err.response.content), err)
File "/usr/local/lib/python3.6/site-packages/future/utils/__init__.py", line 398, in raise_from
exec(execstr, myglobals, mylocals)
File "<string>", line 1, in <module>
chartmogul.errors.APIError: b'""'
vcrpy depends on yarl in python >= 3.5 but yarl needs Python 3.6 at least. This breaks the tests.
A security vulnerability has been identified in the urllib3 package used in the chartmogul-python library. The details of this vulnerability can be found here.
Is it possible to return a json instead of a promise object for the metrics api?
Hi, I would like to have plans in dictionary format but chartmogul.Plan.all(config, per_page=3)
returns a promise(?).
What is the easiest way to retrieve data from this object?
Thank you very much!
The due date field is optional, so we should allow this to be null. This should do it:
due_date = fields.DateTime(allow_none=True)
I'm trying to use the chartmogul.SubscriptionEvent.create() method using the provided code sample and keep getting the following error: marshmallow.exceptions.ValidationError: {'effective_date': ['Not a valid date.'], 'event_date': ['Not a valid date.']}
I've tried different date formats including using the date package to no avail.
I found that if I change the data type definitions in subscription_event.py from fields.Date() to fields.DateTime() everything works as expected. Also, I notice that almost everywhere a date is used it is a DateTime data type except for here and once instance in metrics.py.
I don't see that this has been reported by anyone else, so possibly there's some other issue. I also don't know if simply changing the data types is an appropriate action. But please let me know how to proceed.
I'm trying Plan.all the example straight from the docs:
>>> chartmogul.__version__
'3.1.2'
>>> result = chartmogul.Plan.all(config, per_page=3).get()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "venv/lib/python3.9/site-packages/promise/promise.py", line 512, in get
return self._target_settled_value(_raise=True)
File "venv/lib/python3.9/site-packages/promise/promise.py", line 516, in _target_settled_value
return self._target()._settled_value(_raise)
File "venv/lib/python3.9/site-packages/promise/promise.py", line 226, in _settled_value
reraise(type(raise_val), raise_val, self._traceback)
File "venv/lib/python3.9/site-packages/six.py", line 719, in reraise
raise value
File "venv/lib/python3.9/site-packages/promise/promise.py", line 87, in try_catch
return (handler(*args, **kwargs), None)
File "venv/lib/python3.9/site-packages/chartmogul/errors.py", line 21, in annotateHTTPError
raise err
File "venv/lib/python3.9/site-packages/promise/promise.py", line 87, in try_catch
return (handler(*args, **kwargs), None)
File "venv/lib/python3.9/site-packages/chartmogul/resource.py", line 111, in _load
return cls._loadJSON(jsonObj)
File "venv/lib/python3.9/site-packages/chartmogul/resource.py", line 117, in _loadJSON
return cls._many(
TypeError: <lambda>() got an unexpected keyword argument 'has_more'
Seems to happen regardless of whether there actually is more than a single page of data or not. I added querystring terms to just fetch a single plan and it raises the same error.
However, a similar query on another paginated endpoint works fine:
result = chartmogul.Invoice.all(config, per_page=3).get()
Hi @swember and @pkopac, I'm opening a new issue as #80 is now closed.
I'm seeing this issue too. Are you sure this fix was deployed? Or maybe this bug has made its way back into production again?
Code:
invoices = chartmogul.Invoice.all(config,external_id=order_id).get();
Error:
TypeError: () got an unexpected keyword argument 'has_more'
I've checked the API and it is returning a field called has_more on the JSON payload, but it seems that the invoice schema doesn't handle this.
If anyone is experiencing this issue, changing invoice.py
_many = namedtuple('Invoices', [_root_key, "current_page", "total_pages", "customer_uuid"])
to
_many = namedtuple('Invoices', [_root_key, "current_page", "total_pages", "has_more", "customer_uuid"])
fixes the issue.
customer.py line 69 is
website_url = fields.String()
should be
website_url = fields.String(allow_none=True)
this causes request to fail request validation in example code
chartmogul_config = chartmogul.Config(chartmogul_API_key)
chartmogul.Customer.all(chartmogul_config, cursor=cursor).get()
modifying field property fixes this issue in chartmogul-4.2.0
Due to empty plan_uuid fields, our ETL is breaking with promise not valid error marshmallow.exceptions.ValidationError: {118: {'line_items': {0: {'plan_uuid': ['Field may not be null.']}}}}
not allowing us to get any invoices even though only one invoice has empty plan_uuid.
I'm wondering if plan_uuid could be considered optional (and what the overall impact would be) by changing, plan_uuid = fields.String(allow_none=True)
inside invoices.py
Found an error in the API docs on https://dev.chartmogul.com/reference/delete-all-customers-invoices
The example for Python just gives an error.
>>> chartmogul.Invoice.destroy_all(
... config,
... 'ds_fef05d54-47b4-431b-aed2-eb6b9e545430',
... 'cus_f466e33d-ff2b-4a11-8f85-417eb02157a'
... ).get()
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: fc() takes 2 positional arguments but 4 were given
It looks like the required syntax is this (named keywords instead of positional):
chartmogul.Invoice.destroy_all(
config,
data_source_uuid='ds_fef05d54-47b4-431b-aed2-eb6b9e545430',
customer_uuid='cus_f466e33d-ff2b-4a11-8f85-417eb02157a'
).get()
Hello, a few hours ago I started experiencing issues with your Python wrapper getting this error (when importing chartmogul):
Python transformation failed: __init__() got an unexpected keyword argument 'strict'
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "/usr/local/lib/python3.7/site-packages/chartmogul/__init__.py", line 5, in <module>
from .api.activity import Activity
File "/usr/local/lib/python3.7/site-packages/chartmogul/api/activity.py", line 6, in <module>
class Activity(Resource):
File "/usr/local/lib/python3.7/site-packages/chartmogul/api/activity.py", line 29, in Activity
_schema = _Schema(strict=True)
TypeError: __init__() got an unexpected keyword argument 'strict'
Script failed.
I dug into your code only to find out that marshmallow has updated to 3.0.0 and this causes the issue in your code. I quickly fixed this by installing marshmallow version 2.20.1. Maybe you want to fix that as well.
Calling
chartmogul.imp.Invoice.all(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb').get()
for a valid config and existing customer uuid raises a TypeError.
Full stacktrace:
/.venv/lib/python3.5/site-packages/promise/promise.py in get(self, timeout)
198 elif self.state == self.FULFILLED:
199 return self.value
--> 200 raise self.reason
201
202 def wait(self, timeout=None):
/.venv/lib/python3.5/site-packages/promise/promise.py in call_and_reject(r)
344 try:
345 if callable(failure):
--> 346 ret.fulfill(failure(r))
347 else:
348 ret.reject(r)
/.venv/lib/python3.5/site-packages/chartmogul/errors.py in annotateHTTPError(err)
19 raise_from(APIError(err.response.content), err)
20 else:
---> 21 raise err
/.venv/lib/python3.5/site-packages/promise/promise.py in call_and_fulfill(v)
331 try:
332 if callable(success):
--> 333 ret.fulfill(success(v))
334 else:
335 ret.fulfill(v)
/.venv/lib/python3.5/site-packages/chartmogul/resource.py in _load(cls, response)
94 if '_root_key' in dir(cls) is not None and cls._root_key in jsonObj:
95 return cls._many(cls._schema.load(jsonObj[cls._root_key], many=True).data,
---> 96 **{key: jsonObj[key] for key in LIST_PARAMS if key in jsonObj})
97 else:
98 return cls._schema.load(jsonObj).data
TypeError: __new__() got an unexpected keyword argument 'customer_uuid'
Github has started actively warning people about future
. Is it actually needed in this project? The last commit to future
is 2019 so it's unlikely a patch will occur (though a PR is pending).
Open issue with future
: PythonCharmers/python-future#612
Perhaps it's time to drop Python 2 support and remove this dependency?
I'm running into the same issue as this โ #79
req = chartmogul.Invoice.all(config, per_page=pp)
response = req.get()
The code above produces the error <lambda>() got an unexpected keyword argument 'has_more'
This script has been running perfectly for several months, so it seems like a recent change
I'm getting a TypeError <lambda>() got an unexpected keyword argument 'cursor'
after several months of successfully using the same API call req = chartmogul.Activity.all(config, start_date=from_date, per_page=pp)
Have there been any API changes that might be causing this? Is there anything else that I might be missing?
Getting below error for chartmogul.Ping.ping(config).get()
pip install chartmogul==1.2.0
Traceback (most recent call last):
File "chartmogul_util.py", line 11, in <module>
chartmogul.Ping.ping(config).get()
File "/Library/Python/2.7/site-packages/promise/promise.py", line 510, in get
return self._target_settled_value(_raise=True)
File "/Library/Python/2.7/site-packages/promise/promise.py", line 514, in _target_settled_value
return self._target()._settled_value(_raise)
File "/Library/Python/2.7/site-packages/promise/promise.py", line 224, in _settled_value
reraise(type(raise_val), raise_val, self._traceback)
File "/Library/Python/2.7/site-packages/promise/promise.py", line 85, in try_catch
return (handler(*args, **kwargs), None)
File "/Library/Python/2.7/site-packages/chartmogul/errors.py", line 21, in annotateHTTPError
raise err
TypeError: __init__() got an unexpected keyword argument 'status'
Hi, are you considering upgrade of the Marshmallow version to the v3.x? We're using chartmogul in our project and it's our only blocker for upgrading the Marshmallow to v3.
Thanks!
Very basic initial tests with this resulted in issues. Anyone find a resolution?
Simple ping script per documentation:
`import chartmogul
config = chartmogul.Config('TOKEN','SECRET')
chartmogul.Ping.ping(config).get()'
Result:
'Traceback (most recent call last):
File "./ping.py", line 2, in
import chartmogul
File "/Library/Python/2.7/site-packages/chartmogul/init.py", line 2, in
from .api.config import Config
ImportError: No module named api.config`
Hi, I'm using library version 2.1.0 (current release), and am having trouble with response deserialization in Marshmallow.
I'm sending an invoice create that looks like this:
chartmogul.Invoice.create(self.config, uuid=key, data={"invoices": invoices}).get()
The value of invoices is an array that includes all of the proper fields.
During the response cycle, the library deserializes the API's JSON response into Marshmallow models, using the Schema meta class. During this process, if there are any fields from the API that are NOT found in the Marshmallow models, you will get a marshmallow.exceptions.ValidationError
.
I'm guessing you have added a few new fields to the API response, but the library is not aware of them. In my case, I'm seeing the following stack trace:
<class 'marshmallow.exceptions.ValidationError'>
{0: {'line_items': {0: {'transaction_fees_currency': ['Unknown field.'], 'discount_description': ['Unknown field.']}}}}
File <redacted>
chartmogul.Invoice.create(self.config, uuid=key, data={"invoices": invoices}).get()
File "/usr/local/lib/python3.8/dist-packages/promise/promise.py", line 512, in get
return self._target_settled_value(_raise=True)
File "/usr/local/lib/python3.8/dist-packages/promise/promise.py", line 516, in _target_settled_value
return self._target()._settled_value(_raise)
File "/usr/local/lib/python3.8/dist-packages/promise/promise.py", line 226, in _settled_value
reraise(type(raise_val), raise_val, self._traceback)
File "/usr/local/lib/python3.8/dist-packages/six.py", line 719, in reraise
raise value
File "/usr/local/lib/python3.8/dist-packages/promise/promise.py", line 87, in try_catch
return (handler(*args, **kwargs), None)
File "/usr/local/lib/python3.8/dist-packages/chartmogul/errors.py", line 21, in annotateHTTPError
raise err
File "/usr/local/lib/python3.8/dist-packages/promise/promise.py", line 87, in try_catch
return (handler(*args, **kwargs), None)
File "/usr/local/lib/python3.8/dist-packages/chartmogul/resource.py", line 93, in _load
return cls._loadJSON(jsonObj)
File "/usr/local/lib/python3.8/dist-packages/chartmogul/resource.py", line 99, in _loadJSON
return cls._many(cls._schema.load(jsonObj[cls._root_key], many=True), **{
File "/usr/local/lib/python3.8/dist-packages/marshmallow/schema.py", line 719, in load
return self._do_load(
File "/usr/local/lib/python3.8/dist-packages/marshmallow/schema.py", line 901, in _do_load
raise exc
These 2 fields, transaction_fees_currency and discount_description, are not in the documentation or the library anywhere, but do appear to be in the JSON response from your API, as mentioned.
Perhaps the Invoice schema meta could be updated to use Marshmallow's IGNORE
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.