Request streaming example does not work in my environment

I am trying to use the Twitter streaming API using Python requests.

The documentation has a simple example :

import requests
import json

r = requests.post('https://stream.twitter.com/1/statuses/filter.json',
    data={'track': 'requests'}, auth=('username', 'password'))

for line in r.iter_lines():
    if line: # filter out keep-alive new lines
        print json.loads(line)

When I do this, the call requests.post()never returns. I experimented and proved that it definitely connects to Twitter and receives data from the API. However, instead of returning a response object, it just sits there, consuming as much data as twitter sends. Judging by the code above, I would expect it to requests.post()return a response object with an open Twitter connection, and I could continue to get the results in real time.

( , , Twitter , Twitter , . r.content , .)

- , requests.post . , , , , . .

:

  • Python 2.7
  • Ubuntu 11.04
  • 0.14.0
+5
2

, , , , :

r = requests.post('https://stream.twitter.com/1/statuses/filter.json',
    data={'track': 'requests'}, auth=('username', 'password'),
    prefetch=False)

for line in r.iter_lines():
    if line: # filter out keep-alive new lines
        print json.loads(line)

UPDATE: requests stream prefetch:

r = requests.post('https://stream.twitter.com/1/statuses/filter.json',
    data={'track': 'requests'}, auth=('username', 'password'),
    stream=True)

for line in r.iter_lines():
    if line: # filter out keep-alive new lines
        print json.loads(line)
+10

, , . - post (, , ).

prefetch=False kwarg requests.post().

+5

All Articles