Shared State

Jeff McGee's Blog of Messages Worth Passing

Problems with prefetch in python requests

Posted on Thu 11 April 2013 in Tips

Requests is a great library for making HTTP requests. We're using it quite a bit in Infolab to talk to Twitter. Right before they released version 1.0, Requests made a slight change to its streaming API, so the old code results in this error message:

Traceback (most recent call last):
  File "crawl.py", line 56, in <module>
    main()
  File "crawl.py", line 47, in main
    store_tweets(config,f)
  File "crawl.py", line 22, in store_tweets
    prefetch=False,
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
TypeError: request() got an unexpected keyword argument 'prefetch'

You need to change the call that starts the streaming from something like this:

r = requests.post('http://httpbin.org/stream/20', prefetch=False)

to this:

r = requests.post('http://httpbin.org/stream/20', stream=True)
my photo

Jeff McGee — builder, problem solver, teacher, and general nerd.

Github:
@JeffAMcGee
Twitter:
@JeffAMcGee
Email:
jeffamcgee AT gmail