disqus / python-phabricator

Python bindings for Phabricator
Apache License 2.0
159 stars 66 forks source link

TypeError: <phabricator.Resource object at 0x7f1466aaacd0> is not JSON serializable (certificate) #28

Closed Robpol86 closed 8 years ago

Robpol86 commented 8 years ago

I've started seeing this exception with phabricator 0.5.0 on old hosts using user and cert values instead of tokens.

(env)[me Flask-Variants (branch)]$ cat ~/.arcrc 
{
  "hosts" : {
    "https:\/\/redacted\/api\/" : {
      "user" : "me",
      "cert" : "[redacted, length was 255]"
    }
  }
}
(env)[me Flask-Variants (branch)]$ pip freeze |grep phabricator
phabricator==0.5.0
(env)[me Flask-Variants (branch)]$ python
Python 2.7.10 (default, Aug  7 2015, 18:34:52) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from phabricator import Phabricator, ARCRC
>>> phab = Phabricator()
>>> phab.update_interfaces()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Flask-Variants/env/local/lib/python2.7/site-packages/phabricator/__init__.py", line 363, in update_interfaces
    interfaces = query()
  File "Flask-Variants/env/local/lib/python2.7/site-packages/phabricator/__init__.py", line 233, in __call__
    return self._request(**kwargs)
  File "Flask-Variants/env/local/lib/python2.7/site-packages/phabricator/__init__.py", line 284, in _request
    "params": json.dumps(kwargs),
  File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <phabricator.Resource object at 0x7f1466aaacd0> is not JSON serializable
>>> from pprint import pprint
>>> pprint(ARCRC)
{u'conduit_uri': u'https://redacted/',
 u'git.default-relative-commit': u'origin/master',
 u'hosts': {u'https://redacted/api/': {u'cert': u'[redacted, length was 255]',
                                                    u'user': u'me'}}}
>>> 

Works fine on a host using a token. Also on this old host phabricator 0.4.0 works fine too.

(env)[me Flask-Variants (branch)]$ pip install -U phabricator==0.4.0
Downloading/unpacking phabricator==0.4.0
  Using download cache from [redacted]phabricator-0.4.0.tar.gz
  Running setup.py egg_info for package phabricator

    warning: no previously-included files matching '*~' found anywhere in distribution
Installing collected packages: phabricator
  Found existing installation: phabricator 0.5.0
    Uninstalling phabricator:
      Successfully uninstalled phabricator
  Running setup.py install for phabricator

    warning: no previously-included files matching '*~' found anywhere in distribution
Successfully installed phabricator
Cleaning up...
(env)[me Flask-Variants (branch)]$ python
Python 2.7.10 (default, Aug  7 2015, 18:34:52) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from phabricator import Phabricator, ARCRC
>>> phab = Phabricator()
>>> phab.update_interfaces()
>>> from pprint import pprint
>>> pprint(ARCRC)
{u'hosts': {u'https://redacted/api/': {u'cert': u'[redacted, length was 255]',
                                                    u'user': u'me'}}}
>>>