0

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!

pauliwago
  • 6,373
  • 11
  • 42
  • 52
  • What does `print r1.status, r1.length` say with your 'faulty' query? – robertklep Mar 09 '13 at 08:28
  • `400` and `0`, respectively – pauliwago Mar 09 '13 at 08:33
  • When I do it with the 2nd implementation, I get `200` and `1756`, respectively – pauliwago Mar 09 '13 at 08:37
  • I get `200` and `0` for both implementations, although both implementations I had to guess on some missing code because neither is a complete example. Post complete, short, working examples exhibiting reproducible behavior. – Mark Tolonen Mar 09 '13 at 08:46
  • I get `200` and a varying size (which is to be expected) for both (I used the values from the second as the values of the variables used in the first). `400` means `Bad Request`, btw. – robertklep Mar 09 '13 at 09:01

1 Answers1

0

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.

pauliwago
  • 6,373
  • 11
  • 42
  • 52