Ich habe Probleme mit pycurl in Verbindung mit Twitter Streaming API Filter Stream. Was passiert, wenn ich den Code unter dem Code ausführe, scheint es beim Aufruf zu stören. Ich weiß das, weil ich Print-Anweisungen vor und nach dem Call durchgeführt habe. Ich benutze Python 2.6.1 und ich bin auf einem Mac, wenn das wichtig ist.Python: Twitter Streaming und pycurl Probleme
#!/usr/bin/python
print "Content-type: text/html"
print
import pycurl, json, urllib
STREAM_URL = "http://stream.twitter.com/1/statuses/filter.json?follow=1&count=100"
USER = "user"
PASS = "password"
print "<html><head></head><body>"
class Client:
def __init__(self):
self.buffer = ""
self.conn = pycurl.Curl()
self.conn.setopt(pycurl.POST,1)
self.conn.setopt(pycurl.USERPWD, "%s:%s" % (USER,PASS))
self.conn.setopt(pycurl.URL, STREAM_URL)
self.conn.setopt(pycurl.WRITEFUNCTION, self.on_receive)
try:
self.conn.perform()
self.conn.close()
except BaseException:
traceback.print_exc()
def on_receive(self,data):
self.buffer += data
if data.endswith("\r\n") and self.buffer.strip():
content = json.loads(self.buffer)
self.buffer = ""
print content
if "text" in content:
print u"{0[user][name]}: {0[text]}".format(content)
client = Client()
print "</body></html>"
Gibt es überhaupt OAuth mit Pycurl oder muss ich eine andere Route mit Python gehen, um die Streaming API zu verwenden? – calmcajun
Versuchen Sie http://code.google.com/p/oauth/ – Johnsyweb
Oder etwas wie http://code.google.com/p/python-twitter/ vielleicht? Keine Notwendigkeit, das Rad neu zu erfinden. –