To fight Corona Virus, our Prime Minister has declared lockdown for 21 days in all over the country. And so, our college decided to take online lec...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks! This is very useful! I came here because I was searching to see if there's some kind of API to submit Google forms (my kids' school also has us submitting forms every day :)
I didn't think it would be as simple as sending a POST request to the
/formResponse
endpoint 😂I'm glad that this helped you. 👍😄
Great post, James! I needed to do a similar task with google forms, and this was very helpful. However, it didn't work right off the bat for me. After using
requests.post(url, data=d)
, I got the status code401
(which stands for an Unauthorized Error).Side Note: no error is actually thrown. To view the status code, print the object or use
r.status_code
.However, I was able to find a solution, and for the sake of the other readers I wanted to share it here. Here's what I did:
First, I filled out the form using chrome. After submitting the form, I used the developer tools in Chrome (on the landing page of the form) to look at the headers. That can be found on the Network tab after selecting the
formResponse
entry. For anyone following along, there should be a list of several header categories including General, Response Headers, Request Headers, and Form Data.Another Side Note: all of the field names with the data you entered in the Google Form can be found under Form Data; I found that using this was a lot easier than hunting through html tag attributes.
Anyways, Request Headers is the one you want. Now, I'm not sure if you need every single field under the Request Headers, but I decided to use all of them. To do this, I just copied the plain text under Request Headers and assigned it to a variable like this:
Then, I parsed the string using this function:
This returns a dictionary with all of the fields and values under Request Headers. Now, let's parse the header and make the request (to submit the Google Form).
I hope this helps!
I found this helpful, Simon. I did some experiments to figure out what parts of the headers were needed and I was able to get it down to only one: The
cookie:
line.My concern is that this cookie will eventually expire, so hardcoding it may not be a long term solution.
Hey Simon, Thank you for your feedback. I'm glad, it helped you. About Error 401, I didn't ran into this, and I think it's because of the url. Have you changed your google form url as mentioned in the post? You've to change the
/viewform
to/formResponse
at the end of the url. I'm not sure if this will prevent the 401 error but I guess, this should work.And about Form Data, thank you so much about that. Finding attributes from the developer tools is the most tiresome work in this script.
Again, thanks for your comment! And it feels good when someone uses your script and tells you how can you improve it!😄
I did use
/formResponse
. However, I didn't make the form, so there might be some setting differences... I'm not sure. Thanks again, though.how i can get the header text please?
Here's a screenshot:
It's under Network, click the
fromResponse
request, then make sure you're on the header tab and look for "Response Headers."Thanks a lot
its not working in form which has set response receipt always,
No that's not the case. As I've tried it on such form which sends a response receipt.
I'm having the same issue with a test form. If I set "response receipts" to "Always" I only ever get error 400. if I set "response receipts" to "If respondent requests it" I am able to get the form to submit.
Any thoughts?
try again bro, i have tried today, its working when i disable this option and getting error 400 when i activate it
The reason why you are getting a response error of 400 is because when using the
requests
module, the posted data is automatically url encoded. Hence posting options that contains characters such as "+", "@" ..etc will cause a bad form error.Hence, one way you can work around this is to have the request post http URL instead by passing a string.
Hope this helps.
Hi, this is a really great guide! However I'm trying to fill out a google doc that is locked to access by members of a certain organization. Can I make this code automatically sign me into my school account before filling out the form? (I've looked through a gazillion solutions for this on GitHub and none of them seem to work. Chances are I'm using them wrong, but try as I might I can't figure out how.)
Error occured HTTPSConnectionPool(host='docs.google.com', port=443): Max retries exceeded with url: /forms/d/1JxbxYl7ZnWTEKtYqVMQJOi_6_cZvTYrDbGsPeNNnGSY/formResponse?edit_requested=true (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
i am having these error ,
I need help. I am trying to use this but for a multiple choice problem. For example, the question is 1 + 1.
The first option is 1, second is 2. How would we do this?
Image of my code: (I basicilly removed everything for a basic one question. )
Url: docs.google.com/forms/d/e/1FAIpQLS...
Good work! I needed to do something like this too with google forms. But, it didn't work because the form had different pages. Do you have a way of solving this? I would like to point out that the response is received for the first page but not received in the subsequent pages.
Your help will be very much appreciated! Thanks!!
Hey, Thank you for the appreciation but I'm afraid I don't know about submission of multipage google forms, but I guess you can search it on google and find a solution. In my opinion, if there isn't a solution for multi page, you can use selenium to automate the process. Hope this helps!
Hey, great work! I am trying to follow the same step but as I am a beginner, not really sure how to go about it. I have a form to fill every day and was thinking about how to automate it. It consists of several fields as well. Let me know if you could help in any way :)
You can find it from the elements tab in dev tools. It's a pretty cumbersome task to find all the entry is, especially when there are lots of fields. In my opinion, you should take a look at the method suggested by Simon in the comments. It's very easy comparing to my entry id method.
I am getting 401 error i.e unauthorized error. How to handle it ?
I am unable to find entiry.id can you help ?
You can find it from the elements tab in dev tools. It's a pretty cumbersome task to find all the entry is, especially when there are lots of fields. In my opinion, you should take a look at the method suggested by Simon in the comments. It's very easy comparing to my entry id method.
I got that :) okay thanks mate
I was searching for this for a long time, thanks very much
For me it says requests does not exist? How do I download it?
nevermind I downloaded it