tweepy / tweepy

Twitter for Python!
https://www.tweepy.org
MIT License
10.52k stars 4.6k forks source link

Stream failed if using oauth authentication if track keyword has space character #134

Closed terrybleger closed 12 years ago

terrybleger commented 13 years ago

So many people thought it was the urllib or httplib fault, but twitter always response 401 Unauthorized.

'i have space character' 'i+have+space+character' 'i%20have%20space%20character'

It's a total useless to escape or even unescape since it was not the urllib problem.

"" total fail if there is any space character inside track "" auth = tweepy.auth.OAuthHandler('consumer_key', 'consumer_secret') auth.set_access_token('oauth_token', 'oauth_secret')

"" works like a charm but twitter said they will eradicate this using "" auth = tweepy.auth.BasicAuthHandler('my_user', 'my_pass')

stream = Stream(auth, StreamListener()) stream.filter(follow=None, track='i have space character', async=False, locations=None, count=None)

coldclimate commented 12 years ago

I can confirm this works, but is this a tweepy problem or a twitter streaming api problem?

ChoppedLiverMM commented 12 years ago

I've been reading on this the last few days, and best I can tell, the Twitter Streaming API requires Basic Auth, not Oauth. I'd be willing to bet there is something ugly in the backend and the Streaming API will take a while to follow the rest if the Twitterverse.

silviojr commented 12 years ago

Well, this is probably the best solution. But the problem is: the url is not being encoded properly - I mean, whitespaces in the urls should be replaced by "%20" but they are being replaced by "+". So I edited the steaming.py file (in my ubuntu system it is located at /usr/local/lib/python/dist-packages/tweepy-1.8-py2.7.egg/tweepy/streaming.py). After the following line: self.body = urllib.urlencode(self.parameters)

I added: self.body = self.body.replace("+","%20") I'm noob to tweepy and python. You'll probably find better solutions.

joshthecoder commented 12 years ago

Committed a fix for this into master branch. Should be available in Release 1.10.