dazzcreations / otterapi

Automatically exported from code.google.com/p/otterapi
0 stars 0 forks source link

400 error inconsistency #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. in python:
import urllib2
temp = urllib2.urlopen('http://otter.topsy.com/search.json?q="Netflix customers 
see red after price hike"&window=h3')

2. you will get a 400 error
3. but if you type the url in the browser:
http://otter.topsy.com/search.json?q="Netflix customers see red after price 
hike"&window=h3
you get a json file with the correct results.

What is the expected output? What do you see instead?
I expect to get the same response from both methods. it seems that there is a 
bug and your system gives a 400 error to urlopen2

What version of the product are you using? On what operating system?
python 2.6.5
linux

Please provide any additional information below.

Original issue reported on code.google.com by roja.ban...@gmail.com on 19 Jul 2011 at 12:28

GoogleCodeExporter commented 8 years ago
Your browser is being smart and url encoding what you type in the address bar. 
Python assumes you know how to create a valid url and will happily let you make 
bad requests. This will fix your code:

import urllib2
from urllib import urlencode
temp = urllib2.urlopen('http://otter.topsy.com/search.json?' + 
urlencode(dict(q='"Netflix customers see red after price hike"', window='h3')))

Original comment by jason%to...@gtempaccount.com on 19 Jul 2011 at 1:41