我正在尝试从tradeking(https://developers.tradeking.com/documentation/node-streaming)调用实时流式api
以下是我的代码:
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()
以下是我的错误。 ChunkedEncodingError:('连接断开:不完全读取(0字节读取)',不完整读取(0字节读取))
我做错什么了?在
我认为异常是在
s.get(...)
中引发的,它将执行实际的httpget操作并返回一个Response
对象。在处理准备好的请求的后续行看起来是错误的,并且不会对
Response
对象起作用,但是由于异常,代码没有被执行。在尝试将
stream=True
添加到请求中,然后迭代响应:相关问题 更多 >
编程相关推荐