I am trying to write a scipt which will take a movie name, search it in google with 'I am Feeling lucky' and return the redirected page.

import urllib.request
import urllib.response
import urllib.parse


proxy=urllib.request.ProxyHandler({"http":"http://www-proxy.us.oracle.com:80"})
auth=urllib.request.HTTPBasicAuthHandler()
opener=urllib.request.build_opener(proxy,auth,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)

url= 'http://www.google.co.in/search'
values = {'hl' : 'en',
          'q' : 'Departed imdb',
          'btnI' : 'I\'m Feeling Lucky' }

data = urllib.parse.urlencode(values)
req = urllib.request.Request(url, data)
print(req.get_origin_req_host())
response = urllib.request.urlopen(req)
urlresponse = response.geturl()
print(urlresponse)

But it gives me this error :

www.google.co.in
Traceback (most recent call last):
  File "D:\Scripts\imdb.py", line 19, in <module>
    response = urllib.request.urlopen(req)
  File "D:\ProgramFiles\Python30\lib\urllib\request.py", line 122, in urlopen
    return _opener.open(url, data, timeout)
  File "D:\ProgramFiles\Python30\lib\urllib\request.py", line 364, in open
    response = meth(req, response)
  File "D:\ProgramFiles\Python30\lib\urllib\request.py", line 476, in http_response
    'http', request, response, code, msg, hdrs)
  File "D:\ProgramFiles\Python30\lib\urllib\request.py", line 402, in error
    return self._call_chain(*args)
  File "D:\ProgramFiles\Python30\lib\urllib\request.py", line 336, in _call_chain
    result = func(*args)
  File "D:\ProgramFiles\Python30\lib\urllib\request.py", line 484, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Method Not Allowed

Google appears to be blocking the method you're using. Have you tried any debugging?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.