ssfrr / chainclient.py Goto Github PK
View Code? Open in Web Editor NEWA Python client for the Chain API
A Python client for the Chain API
Looks like Requests tells you if the response is the result of a redirect, so we should check that and update the URL so we don't need to redirect next time we visit the URL.
In at least one instance we have a report of chainclient.get()
being called with auth information, and then after navigating down a few levels and calling create()
with no auth=
field, no auth information is transmitted.
This needs more testing, maybe somewhere the auth info isn't being passed down to children.
Once you've retrieved a resource, there's no way to ask the library to refresh the resource from the server data.
We changed some of the URL structure in ChainAPI, and the plan was to do 301 redirects so clients holding old URLs would still work fine, but it turns out redirects and POSTs don't play nicely, so clients with cached POST URLs were SOL.
ChainClient could automatically keep a reference to where it got each link from, and then if it ever gets a 404 it could re-request that object (and recursively do the same thing if THAT request gave a 404). That would be transparent from the application side.
When a link has a templated field, chainclient should support filling in the fields using keyword args
A authorization may have occurred while running the tidpost collector of ChainAPI with ChainClient 0.4.0. After reverting to 0.3.0, the bug disappeared; however, the bug was not reproduceable upon returning to 0.4.0.
The output of the tidpost script which failed was:
vagrant@vagrant-ubuntu-trusty-64:/vagrant/collectors$ ./tidpost http://127.0.0.1/sites/1
('yoda', '123')
2014-10-24 20:58:21 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:21 vagrant-ubuntu-trusty-64 __main__[2143] INFO Connecting to TidSense stream at tcp://127.0.0.1:5556
2014-10-24 20:58:21 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:21 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 __main__[2143] INFO Received: {u'src': u'0x816F', u'via': u'0xFFFF', u'sht_humidity': 38.6, u'bmp_pressure': 1003.27, u'battery_voltage': 4.44, u'illuminance': 0, u'sht_temperature': 23.84, u'bmp_temperature': 23.3}
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 __main__[2143] INFO Posting sht_humidity data: {'timestamp': '2014-10-24T20:58:32.755569+00:00', 'value': 38.6}
2014-10-24 20:58:32 vagrant-ubuntu-revertedtrusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 __main__[2143] INFO Posting bmp_pressure data: {'timestamp': '2014-10-24T20:58:32.755569+00:00', 'value': 1003.27}
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 __main__[2143] INFO Posting battery_voltage data: {'timestamp': '2014-10-24T20:58:32.755569+00:00', 'value': 4.44}
2014-10-24 20:58:32 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:33 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:33 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
2014-10-24 20:58:33 vagrant-ubuntu-trusty-64 __main__[2143] INFO Posting illuminance data: {'timestamp': '2014-10-24T20:58:32.755569+00:00', 'value': 0}
2014-10-24 20:58:33 vagrant-ubuntu-trusty-64 urllib3.connectionpool[2143] INFO Starting new HTTP connection (1): 127.0.0.1
Traceback (most recent call last):
File "./tidpost", line 173, in <module>
main()
File "./tidpost", line 86, in main
post_sensor_data(dev_json, dev)
File "./tidpost", line 165, in post_sensor_data
history.create(sensor_data, cache=False)
File "build/bdist.linux-x86_64/egg/chainclient.py", line 242, in create
File "build/bdist.linux-x86_64/egg/chainclient.py", line 37, in _request_with_error
chainclient.ChainException: Unauthorized, please authenticate the request with auth=("user", "pass")
As you can see, multiple successful POST requests were made before the script finally failed. The authorization failure resulted from a 401 sent from Nginx (which handles authorization with the .htpasswd file), so the 401 will not show up in the Django log for ChainAPI. Upon debugging with PDB, we noticed that the value of auth
in ChainClient when it fails is None
, despite the fact that ('yoda', '123')
(the correct username and password for the development server) were being used in the tidpost script.
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.