Giter Site home page Giter Site logo

beanbag's People

Contributors

ajtowns avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

beanbag's Issues

tests fail with python 3.6

(master)mwhudson@aeglos:/opt/opensource/deb/beanbag$ PYTHONPATH=. python3.6 `which py.test-3`
======================================================== test session starts =========================================================
platform linux -- Python 3.6.1, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: /opt/opensource/deb/beanbag, inifile: 
collected 4 items 

tests/test_attrdict.py .
tests/test_bbv1.py .
tests/test_bbv2.py .F

============================================================== FAILURES ==============================================================
_______________________________________________________ test_sane_inheritance ________________________________________________________

    def test_sane_inheritance():
>       class MyBeanBag(BeanBag):
E       TypeError: __class__ set to <class 'test_bbv2.test_sane_inheritance.<locals>.MyBeanBagBase'> defining 'MyBeanBag' as <class 'test_bbv2.test_sane_inheritance.<locals>.MyBeanBag'>

tests/test_bbv2.py:44: TypeError
================================================= 1 failed, 3 passed in 0.20 seconds =================================================

I haven't looked into this at all!

How to access response headers?

While trying to access gitlab api and dealing with pagination, i need access to the resonse headers.

As it looks from the code the response header is thrown away in the decode() function.

Is there a workaround i can use?
I was trying to simply subclass BeanBag but that complained about missing:

AttributeError: 'MyBeanBagBase' object has no attribute 'base_url'

Kind regards

Hauke

Doesn't handle 404 responses

Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import beanbag, pdb; g = beanbag.BeanBag("https://api.github.com/rubbish")
>>> g.rubbish1()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/beanbag/__init__.py", line 159, in __call__
    return self.__bbr.make_request(verb, self.__path, kwargs, body)
  File "/usr/local/lib/python2.7/dist-packages/beanbag/__init__.py", line 285, in make_request
    % (r.status_code, r.reason),
AttributeError: 'Response' object has no attribute 'reason'
>>> pdb.pm()
> /usr/local/lib/python2.7/dist-packages/beanbag/__init__.py(285)make_request()
-> % (r.status_code, r.reason),
(Pdb) p dir(r)
['__bool__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_content', '_content_consumed', 'config', 'content', 'cookies', 'encoding', 'error', 'headers', 'history', 'iter_content', 'iter_lines', 'json', 'ok', 'raise_for_status', 'raw', 'request', 'status_code', 'text', 'url']
(Pdb) p r.status_code
404

The cause

Apparently a request doesn't have a r.reason on a 404. (I've not used request, so I don't know why not.)

verify=false doesn't work

If one sets session.verify=False subsequent request() calls of request module - session.request doesn't take this into account. Apparently one needs to set verify as a request() attribute.

So url_v1.py could be fixed with

r = self.session.request(verb, path, params=params, data=ebody, verify=self.session.verify)

Changing mime_type

Some REST frame works require changing the mime type for every request (yes, this does seem dodgy). However there doesn't seem to be a good way to do this with beanbag. For now I have used the ugly solution:

(~gh)[0].mime_json = "application/vnd.com.nsn.cumulocity.managedObjectCollection+json"

beanbag.BeanBagException: Could not decode response

Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import beanbag, pdb; g = beanbag.BeanBag("https://api.github.com")
>>> g.repos.ajtowns.beanbag()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/beanbag/__init__.py", line 159, in __call__
    return self.__bbr.make_request(verb, self.__path, kwargs, body)
  File "/usr/local/lib/python2.7/dist-packages/beanbag/__init__.py", line 296, in make_request
    r, (verb, path, params, ebody))
beanbag.BeanBagException: Could not decode response

The cause

  • The line that failed is self.decode(r).
  • self.decode == lambda req: req.json().
  • type(r.json) == dict.
  • dict isn't callable.

Suggestion

When you report the error (ie, in the raise BeanBagException()), include the reason from the inner exception in the text (ie, str(sys.exc_info()[1])).

Access original JSON data

For some complicated rest APIs , it is necessarily to be able to access the original JSON data. E.g. so the entire response can be stored in a JSONField in the database. It looks like this data is stored in the AttrDict as base, but this value is not accessible.

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.