Reputation: 3855
I am trying to call live streaming api from tradeking (https://developers.tradeking.com/documentation/node-streaming)
Following is my code:
import requests
from requests_oauthlib import OAuth1
CK = "CK"
CS = "CS"
OT = "OT"
OS ="OS"
def read_stream():
s = requests.Session()
s.auth = OAuth1(CK, CS, OT, OS, signature_type='auth_header')
symbols = ["APPL", "GOOG"]
payload = {'symbols': ','.join(symbols)}
headers = {'connection': 'keep-alive', 'content-type': ' application/json', 'x-powered-by': 'Express', 'transfer-encoding': 'chunked'}
req = s.get('https://stream.tradeking.com/v1/market/quotes.json',
params=payload)
prepped = s.prepare_request(req)
resp = s.send(prepped, stream=True)
for line in resp.iter_lines():
if line:
print(line)
read_stream()
Following is my error. "ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))"
What I am doing wrong?
Upvotes: 0
Views: 372
Reputation: 87074
I think that the exception is raised in s.get(...)
which will perform an actual HTTP GET operation and return a Response
object.
The subsequent lines dealing with prepared requests seem wrong and won't work on Response
objects, but that code is not being executed due to the exception.
Try adding stream=True
to the request and then iterate over the response:
resp = s.get('https://stream.tradeking.com/v1/market/quotes.json', stream=True, params=payload)
for line in resp.iter_lines():
if line:
print(line)
Upvotes: 1