Understanding Python HTTP streaming -


i'm struggling access streaming api using python , requests.

what api says: "we’ve enabled streaming endpoint requesting both quote , trade data utilizing persistent http socket connection. streaming data api consists of making authenticated http request , leaving http socket open continually receive data."

how i've been trying access data:

s = requests.session() def streaming(symbols):     url = 'https://stream.tradeking.com/v1/market/quotes.json'     payload = {'symbols': ','.join(symbols)}     return s.get(url, params=payload, stream=true)   r = streaming(['aapl', 'goog']) 

the requests docs here show 2 things of interest: use generator/iterator use chunked data, passed in data field. streaming data, suggests using code such as:

for line in r.iter_lines():     print(line) 

neither seem work, although i've no idea put in generator function, since example unclear. using r.iter_lines(), output: "b'{"status":"connected"}{"status":disconnected"}'"

i can access headers, , response http 200, can't valid data, or find clear examples on how access streaming http data in python. appreciated. api recommends using jetty java keep stream open, i'm not sure how in python.

headers: {'connection': 'keep-alive', 'content-type': 'application/json', 'x-powered-by': 'express', 'transfer-encoding': 'chunked'}

not sure if figured out, tradeking doesn't put newlines in between json blobs. have use iter_content byte byte, append byte buffer, try decode buffer, on success clear buffer , yield resultant object. :(


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -