I have a piece of code like this
host = \'http://www.bing.com/search?q=%s&go=&qs=n&sk=&sc=8-13&first=%s\' % (query, page)
req = urllib2.
I also encountered the same problem. Turns out the problem was the method was set inappropriately. When you include urlencoded data in urllib2.urlopen () the method should be set to POST and when you exclude it, method should be GET. So, how do you set the method is given below:
For POST request
request_object = urllib2.Request(url)
method = ("POST", "GET")
request_object.get_method = lambda: method[0] #If method is set to POST
url_handle = opener.open(req, data) #If method is set to POST
For GET request
request_object = urllib2.Request(url)
method = ("POST", "GET")
request_object.get_method = lambda: method[1] #If method is set to GET
url_handle = opener.open(req) #If method is set to GET
This will set your url request method to the appropriate required method