searchTwitter() does not encode query #25

Closed
opened 2010-11-27 23:07:59 -08:00 by momander · 1 comment
momander commented 2010-11-27 23:07:59 -08:00 (Migrated from github.com)

I believe the searchTwitter() method does not encode the query properly.

from twython import Twython
query = ""mountain view""
search_results = twitter.searchTwitter(q=query, rpp=2)
for tweet in search_results["results"]:
print tweet["text"]

Expected result:
Only tweets with the string "mountain view" (name of the city) should appear.

Actual result:
Most returned tweets contain only the word "mountain".

My ugly fix right now is to use urllib.quote_plus(), see below. It gets the expected behavior, but it would be great if this fix were worked into the library.

from twython import Twython
query = ""mountain view""
search_results = twitter.searchTwitter(q=urllib.quote_plus(query), rpp=2)
for tweet in search_results["results"]:
print tweet["text"]

I believe the searchTwitter() method does not encode the query properly. > from twython import Twython > query = "\"mountain view\"" > search_results = twitter.searchTwitter(q=query, rpp=2) > for tweet in search_results["results"]: > print tweet["text"] Expected result: Only tweets with the string "mountain view" (name of the city) should appear. Actual result: Most returned tweets contain only the word "mountain". My ugly fix right now is to use urllib.quote_plus(), see below. It gets the expected behavior, but it would be great if this fix were worked into the library. > from twython import Twython > query = "\"mountain view\"" > search_results = twitter.searchTwitter(q=urllib.quote_plus(query), rpp=2) > for tweet in search_results["results"]: > print tweet["text"]
ryanmcgrath commented 2010-11-28 01:02:44 -08:00 (Migrated from github.com)

Committed and fixed. Twython 1.3.5 is now patched to handle this scenario; it'd be on Pypi, but apparently the damn thing can't stay up for more than a few hours at a time. ;P

Enjoy, though, and feel free to hit me up if you see anything else like this.

Committed and fixed. Twython 1.3.5 is now patched to handle this scenario; it'd be on Pypi, but apparently the damn thing can't stay up for more than a few hours at a time. ;P Enjoy, though, and feel free to hit me up if you see anything else like this.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/twython#25
No description provided.