Coder Social home page Coder Social logo

python-maxcdn's People

Contributors

dave-shawley avatar dlitvakb avatar eamonnscu avatar idabic avatar jdorfman avatar jmervine avatar tdondich avatar tonytan4ever avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-maxcdn's Issues

Replace `requests_netdna` with `requests`.

Remove the forked version of requests, in favor of the original request. This should also fix #1, as it seems that requests_netdna has 3.x bugs that aren't in the latest requests module.

API fails to retrieve reseller date based usage stats

Hi
I am trying to execute the reseller usage API for specific dates, and it is not working well.
The following code is an attempt to fetch July data, but all it does is always get the current month to date. Either I am not doing something right with this API, or there is a problem with the endpoint.

My code:

#!/usr/bin/env python
import pprint as pp
from textwrap import dedent
from maxcdn   import MaxCDN
import json 


alias="globaldots"
key="this is my key"
secret="this is my secret"

from_date="2016-07-01"
to_date="2016-07-31"

# report="/monthly"
report=""
date_str="from_date=%s&to_date=%s" % (from_date, to_date)
params={"from_date":from_date, "to_date" : to_date}
maxcdn = MaxCDN(alias, key, secret)

# Get my clients 
clients = maxcdn.get("/clients.json")
i=2
clientid=clients["data"]["accounts"][i]["id"]
clientname=clients["data"]["accounts"][i]["alias"]
clientstatus=clients["data"]["accounts"][i]["status"]

stats_url="/clients/%s/reports/stats.json%s" % (clientid, report)

# Version 1: pass a dictionary of dates
client_stats=maxcdn.get(stats_url, params)
print("Version 1: pass a dictionary of dates")
print json.dumps(client_stats)
print(" ")

# Version 2: pass a query string of dates
client_stats=maxcdn.get(stats_url, params=date_str)
print("Version 2: pass a query string of dates")
print json.dumps(client_stats)
print(" ")

# Version 3: Do not pass any parameters
client_stats=maxcdn.get(stats_url)
print("Version 3: Do not pass any parameters")
print json.dumps(client_stats)
print(" ")

The results are identical - month to date - no matter how I pass the dates, and what type of report I run.

Version 1: pass a dictionary of dates
{"code": 200, "data": {"total": "1", "stats": {"cache_hit": "698300293", "noncache_hit": "1899", "hit": "698302192", "size": "8331462444846"}}}

Version 2: pass a query string of dates
{"code": 200, "data": {"total": "1", "stats": {"cache_hit": "698300293", "noncache_hit": "1899", "hit": "698302192", "size": "8331462444846"}}}

Version 3: Do not pass any parameters
{"code": 200, "data": {"total": "1", "stats": {"cache_hit": "698300293", "noncache_hit": "1899", "hit": "698302192", "size": "8331462444846"}}}

GET body not allowed

I was working on debugging one reported issue with python fetching raw logs via API and found that you are missing definition in get method for body:

def get(self, end_point, *_kwargs):
return self.client.get(self._get_url(end_point),
headers=self._get_headers(json=False),
*_kwargs).json()

should contain "data=None":

def get(self, end_point, data=None, *_kwargs):
return self.client.get(self._get_url(end_point),
headers=self._get_headers(json=False),
*_kwargs).json()

otherwise, exception is thrown as:

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/maxcdn/maxcdn.py", line 40,
in get
*_kwargs).json()
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 468,
in get
return self.request('GET', url, *_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 422,
in request
prep = self.prepare_request(req)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 360,
in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 298, in
prepare
self.prepare_auth(auth, url)
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 475, in
prepare_auth
r = auth(self)
File
"/usr/local/lib/python2.7/dist-packages/requests_oauthlib/oauth1_auth.py",
line 79, in call
unicode(r.url), unicode(r.method), r.body or '', r.headers)
File
"/usr/local/lib/python2.7/dist-packages/oauthlib/oauth1/rfc5849/init.py",
line 287, in sign
raise ValueError('GET/HEAD requests should not include body.')
ValueError: GET/HEAD requests should not include body.

No JSON object could be decoded

I'm having a transient issue with the library. Every so often, the get call below fails. Waiting a few seconds and retrying to call usually fixes it so I suspect the remote server is responding with something unexpected. Clients can easily catch and retry, but it would be nice if the library gracefully failed and gave consumers a clearer picture of the cause so they can adapt appropriately.

start=(datetime.datetime.now() - datetime.timedelta(hours=1)).isoformat()
params = urllib.urlencode({'start': start})
res = api.get("/v3/reporting/logs.json?{0}".format(params))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/maxcdn/maxcdn.py", line 40, in get
    **kwargs).json()
  File "/Library/Python/2.7/site-packages/requests/models.py", line 797, in json
    return json.loads(self.text, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.