【问题标题】:Can't read from Twitter user stream using HTTPSConnection无法使用 HTTPSConnection 从 Twitter 用户流中读取
【发布时间】:2015-07-31 20:16:35
【问题描述】:

我正在尝试使用 Python 的 HTTPSConnection 从我的 Twitter 用户流中读取数据。我可以成功连接并授权到 Twitter 的 API,但是,当我从网站发推文时,没有其他内容被推送到流中。我的代码如下。

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)

【问题讨论】:

    标签: python twitter twitter-oauth


    【解决方案1】:

    原来我一次读取的数据太多。通过将buff = resp.read(8192) 更改为buff = resp.read(1024),我现在可以阅读我的推文了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-06
      • 2015-09-29
      • 2019-05-18
      • 1970-01-01
      • 2017-12-08
      • 2023-03-27
      • 2015-08-03
      • 2012-12-14
      相关资源
      最近更新 更多