I'm having issues using httplib's request() method. It's a really odd problem. My code looks like this:

query = "/search.json?q=&geocode=" + slat + "," + slong + "," + mline[2] + "km&rpp=" + mline[3]
conn = httplib.HTTPConnection("search.twitter.com")
conn.request("GET", query) #request here
r1 = conn.getresponse()
preresult = r1.read()

print preresult

So the problem is, nothing prints out. query is made up of a ton of other strings concatenated. What's really strange is if I set query equal to the actual value of the string (that is, actually set it equal to say, "/search.json?q=&geocode=27.5916,086.5640,100km&rpp=2" as opposed to tons of other strings concatenated), then it prints out as it should. I got that value of query by doing print query after concatenation in the code above. So to make things clear, the following works fine (using the value of print query from above):

query = "/search.json?q=&geocode=27.5916,086.5640,100km&rpp=2"
conn = httplib.HTTPConnection("search.twitter.com")
conn.request("GET", query) #request here
r1 = conn.getresponse()
preresult = r1.read()

print preresult

The value of query should be identical in both implementations. I checked query's type in the 1st implementation to make sure it's a string. But they give different results. Any ideas? Thanks!

有帮助吗?

解决方案

It turns out mline[3] had some invisible character at the end. It wasn't a newline or an whitespace....but I just converted it to an int first, then converted it back to a string and the extra character disappeared and my problem went away. Thanks for all your help.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top