无法使用HTTPSConnection从Twitter用户流读取数据

2024-06-13 22:29:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Python的HTTPSConnection读取Twitter用户流。我可以成功地连接并授权到Twitter的API,但是,当我从web站点发tweet时,没有其他东西被推送到流中。我的代码在下面。你知道吗

import http.client

#Authorization headers cut
authheaders = """OAuth oauth_consumer_key="<snip>", oauth_nonce="<snip>", oauth_signature="<snip>", oauth_signature_method="<snip>", oauth_timestamp="<snip>", oauth_token="<snip>", oauth_version="1.0" """

conn = http.client.HTTPSConnection("userstream.twitter.com:443")
conn.putrequest("GET", "/1.1/user.json")
conn.putheader("Authorization", authheaders)
conn.endheaders()
resp = conn.getresponse()
print("HTTP " + str(resp.status))

while True:
    buff = resp.read(8192)
    if buff != b'':
        print(buff)

Tags: 用户clientapihttptwitterconnoauthresp
1条回答
网友
1楼 · 发布于 2024-06-13 22:29:49

结果我一次读的数据太多了。通过将buff = resp.read(8192)更改为buff = resp.read(1024),我现在可以阅读我的tweet了。你知道吗

相关问题 更多 >