2

I am trying to make a script which will fill the google form using post method. Here is my code:-

import urllib.parse

import urllib.request

user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'
header={'User-Agent' : user_agent}
url = "https://docs.google.com/forms/d/e/1FAIpQLSec7NTUhCXGqeBxUfNraWHAd2Kf8aHg0tVy3fY0*****TF2Kw/"
# values from your form. You will need to include any hidden variables if you want to..
values= {
'Name to display': 'Mayank Test',
'Age':'22',
'Country':'India',
'Username':'user_mayank',
'Email (to share guidelines and confirming username and password)':'*****@gmail.com'
}
data = urllib.parse.urlencode(values).encode("utf-8")
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
the_page = response.read()

and I am getting error:-

Traceback (most recent call last):
  File "C:/Users/MAYANK/Desktop/script_google_form.py", line 17, in <module>
    response = urllib.request.urlopen(req)
  File "I:\Python\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "I:\Python\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "I:\Python\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "I:\Python\lib\urllib\request.py", line 570, in error
    return self._call_chain(*args)
  File "I:\Python\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "I:\Python\lib\urllib\request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Method Not Allowed

I dont know here I am wrong. Help me!! I dont know why not accepting post request

6
  • That error is basically saying that the route/server you're hitting doesn't accept POST requests. It doesn't look like you're doing anything wrong other than trying to send a POST request to a route that doesn't accept POST requests. Are you sure this is possible in the way you're trying to do it? Commented Mar 22, 2018 at 16:03
  • That URL doesn't look valid. "Its full of stars". Commented Mar 22, 2018 at 16:03
  • @zerocool I dont know. google forms accept post request like this. Commented Mar 22, 2018 at 16:05
  • @PeterWood I edited it Commented Mar 22, 2018 at 16:05
  • I think that section was purposefully omitted by the poster. Same with the email address. Commented Mar 22, 2018 at 16:06

1 Answer 1

1

An HTTP 405 error indicates a problem with your script and/or your web server. The error means that you are attempting to pass back a file that does not have the necessary permissions on the server to receive Post information from another script.

Make sure you have disabled one response per person and collect email address options in the form settings.

Here is the code that I use to fill the form. First, go to the form by using the URL in the code below and right click => view source code. There search for entry. you'll find a many. Actually, you need to use the entry.<id> in the data map instead of the field name.

import requests

url = "https://docs.google.com/forms/d/e/1FAIpQLSfZ0-8mzregRLTmn6xo7q05Camz95F4fkWomU5q8OBSnHWg0g/formResponse"

data = {
    "entry.2005620554": "Hii",
    "entry.1045781291": "this",
    "entry.1065046570": "obviously",
    "entry.1166974658": "works",
    "entry.839337160": "like charm",
    "entry.1360790904": "Yes",
}

print(data)
result = requests.post(url, data)
print(result)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.