I’m encountering a puzzling issue while trying to submit a form using Python’s requests library. The code works flawlessly for one form but consistently returns a 405 error for another. Despite double-checking the URL, form field names, and headers, the problem persists. The error indicates that the server is rejecting the HTTP POST method. What could be causing this discrepancy between the two forms? Are there specific server configurations or form settings that might lead to such behavior? I’d greatly appreciate any insights or troubleshooting steps to resolve this issue.
import requests
import random
url = "https://docs.google.com/forms/d/e/1FAIpQLSej-yVBTGxdpdf-SWz2Da4c_ClX666CNnE9LjYrFobOYLmWWQ/viewform"
# Define the lists of options for multiple-choice questions
q2_options = ["21-30", "31-40", "41-50", "50 years old and above"]
q3_options = ["Male", "Female"]
q4_options = ["Single", "Married", "Separated", "Widowed"]
q5_options = ["Diploma", "Bachelor Degree", "Post Graduate", "Doctorate", "Other"]
q6_options = ["25,000-45,000", "45,001-65,000", "65,001-85,000", "85,001-100,000", "Above 100,000"]
q7_options = ["Public Sector", "Private Sector", "Limited Liability Partnership"]
q8_options = ["Top Level", "Midlevel", "Lower Level"]
q9_options = ["Individual Contributor", "Midlevel", "Lower Level"]
q10_options = ["Administration", "Marketing", "Finance", "Human Resources", "Information Technology", "Other"]
q11_options = ["0-6 months", "6-12 months", "1-2 years","More than 2 years"]
q12_options = ["0 days per week", "1-2 days", "2-4 days","More than 2 years"]
q13_options = ["Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"]
q14_options = ["Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"]
q15_options = ["Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"]
q16_options = ["Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"]
q17_options = ["Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"]
q18_options = ["Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"]
q19_options = ["Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"]
q20_options = ["Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"]
# Define the list of names
names = ["Aarav", "Aarya", "Advait", "Akshay", "Aman", "Ananya", "Anika", "Arjun", "Aryan", "Avani", "Dev", "Diya", "Ishaan", "Kabir", "Krishna", "Meera", "Neha", "Nikhil", "Rohan", "Sanya", "Shreya", "Siddharth", "Tanvi", "Ved", "Vidya", "Yash", "Zara"]
# Define the list of company names
companies = ["Tata Group", "Reliance Industries", "Infosys", "Wipro", "HDFC Bank", "ICICI Bank", "State Bank of India", "Aditya Birla Group", "Mahindra Group", "Bharti Airtel", "Amazon", "Google", "Apple", "Microsoft", "Facebook", "IBM", "Tesla", "Nike", "McDonald's", "Coca-Cola", "Toyota", "Samsung", "Sony", "Nestle","Unilever", "Rolls-Royce", "British Airways", "BBC", "Barclays", "BP", "GlaxoSmithKline", "Vodafone"]
# Define the list of email domains
email_domains = ["@gmail.com", "@outlook.com", "@hotmail.com", "@yahoo.com", "@icloud.com"]
# Initialize the list to store the responses
responses = []
# Generate responses
for _ in range(100):
# Randomly select options for multiple-choice questions
q2_option = random.choice(q2_options)
q3_option = random.choice(q3_options)
q4_option = random.choice(q4_options)
q5_option = random.choice(q5_options)
q6_option = random.choice(q6_options)
q7_option = random.choice(q7_options)
q8_option = random.choice(q8_options)
q9_option = random.choice(q9_options)
q10_option = random.choice(q10_options)
q11_option = random.choice(q11_options)
q12_option = random.choice(q12_options)
q13_option = random.choice(q13_options)
q14_option = random.choice(q14_options)
q15_option = random.choice(q15_options)
q16_option = random.choice(q16_options)
q17_option = random.choice(q17_options)
q18_option = random.choice(q18_options)
q19_option = random.choice(q19_options)
q20_option = random.choice(q20_options)
# Randomly select a name and company name
name = random.choice(names)
company = random.choice(companies)
# Generate email using the name
email_domain = random.choice(email_domains)
email = f"{name.lower().replace(' ', '_')}_{random.randint(100, 999)}{email_domain}"
# Define the form data for each response
data = {
"entry.910224750": name, # Q.0 (Name)
"entry.1541298299": company, # Q.1 (Company Name)
"entry.1486496029": q2_option, # Q.2 (Age)
"entry.708803424": q3_option, # Q.3 (Gender)
"entry.1856459579": q4_option, # Q.4 (Marital Status)
"entry.1426574438": q5_option, # Q.5 (Highest Qualification - 1)
"entry.718994745": q5_option, # Q.5 (Highest Qualification - 2)
"entry.143852984": q6_option, # Q.6 (Salary Range)
"entry.1263268158": q7_option, # Q.7 (Type of Company)
"entry.743776256": q8_option, # Q.8 (Level of Management)
"entry.829106370": q9_option, # Q.9 (Position held in the organization)
"entry.1374407437": q10_option, # Q.10 (Job Function)
"entry.1960138": q11_option, # Q.11 (How long working hybrid)
"entry.1763934805": q12_option, # Q.12 (Average days working at home)
"entry.1041497206": q13_option, # Q.13.1 (Working from home - Schedule work convenience)
"entry.599886965": q13_option, # Q.13.2 (Working from home - Select worksite location)
"entry.573774039": q13_option, # Q.13.3 (Working from home - Processes and procedures clarity)
"entry.1125555620": q13_option, # Q.13.4 (Working from home - Flexibility to share workload)
"entry.1081719396": q13_option, # Q.13.5 (Working from home - Organizational support)
"entry.586321667": q14_option, # Q.14.1 (Work-life balance improvement)
"entry.776962631": q14_option, # Q.14.2 (Work-life balance improvement - Hybrid model)
"entry.99323927": q14_option, # Q.14.3 (Work completed within shift)
"entry.1648573820": q14_option, # Q.14.4 (Flexible schedule and freedom)
"entry.687846320": q15_option, # Q.15.1 (Hybrid work culture - Promotion and professional path)
"entry.1224201763": q15_option, # Q.15.2 (Hybrid work culture - Explore professional interest)
"entry.1555884761": q15_option, # Q.15.3 (Hybrid work culture - Spend more time on career growth)
"entry.585175222": q16_option, # Q.16.1 (Satisfaction with flexibility)
"entry.1898438169": q16_option, # Q.16.2 (Recommendation of hybrid work model)
"entry.2054905493": q16_option, # Q.16.3 (Sense of accomplishment)
"entry.737755674": q17_option, # Q.17.1 (Task accomplishment efficiency)
"entry.251507125": q17_option, # Q.17.2 (Productivity enhancement)
"entry.500882328": q17_option, # Q.17.3 (Productivity while working remotely)
"entry.98137193": q17_option, # Q.17.4 (Effect of poor internet or equipment on productivity)
"entry.1476904577": q18_option, # Q.18.1 (Consideration of future hybrid work)
"entry.215224198": q18_option, # Q.18.2 (Intention for future hybrid work)
"entry.405637183": q18_option, # Q.18.3 (Recommendation of peers for hybrid work)
"entry.841682949": q19_option, # Q.19.1 (Benefits of hybrid work - Less absenteeism)
"entry.853361537": q19_option, # Q.19.2 (Benefits of hybrid work - No disruption)
"entry.1225689996": q19_option, # Q.19.3 (Benefits of hybrid work - High productivity)
"entry.669175254": q19_option, # Q.19.4 (Benefits of hybrid work - Flexible work schedule)
"entry.33812326": q19_option, # Q.19.5 (Benefits of hybrid work - Less commuting)
"entry.1473408458": q19_option, # Q.19.6 (Benefits of hybrid work - More control over life)
"entry.395222184": q19_option, # Q.19.7 (Benefits of hybrid work - More time with family)
"entry.76768796": q19_option, # Q.19.8 (Benefits of hybrid work - More employee benefits)
"entry.1613488688": q19_option, # Q.19.9 (Benefits of hybrid work - No benefit realized)
"entry.1379560201": q20_option, # Q.20.1 (Challenges of hybrid work - Collaboration and productivity)
"entry.167367650": q20_option, # Q.20.2 (Challenges of hybrid work - Solving workplace issues after hours)
"entry.104488722": q20_option, # Q.20.3 (Challenges of hybrid work - Home office setup cost)
"entry.1582351756": q20_option, # Q.20.4 (Challenges of hybrid work - Blurry boundaries)
"entry.1956790332": q20_option, # Q.20.5 (Challenges of hybrid work - Isolation and lack of social interaction)
"entry.1130692506": q20_option, # Q.20.6 (Challenges of hybrid work - Lack of concentration/distraction)
"entry.812760415": q20_option, # Q.20.7 (Challenges of hybrid work - Lack of personal interaction and motivation)
"entry.1286972214": q20_option, # Q.20.8 (Challenges of hybrid work - Need for clear daily targets)
"entry.1615336716": q20_option, # Q.20.9 (Challenges of hybrid work - Work completion at home)
"entry.1320478640": "Suggestions", # Q.21 (Suggestions for successful implementation of hybrid setting)
}
# Add the form data to the list of responses
responses.append(data)
# Define the headers
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Origin": "https://docs.google.com",
"Referer": "https://docs.google.com/forms/d/e/1FAIpQLSej-yVBTGxdpdf-SWz2Da4c_ClX666CNnE9LjYrFobOYLmWWQ/viewform",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299",
}
# Send the POST requests for each response
for data in responses:
response = requests.post(url, data=data, headers=headers)
if response.status_code == 200:
print("Form submitted successfully!")
else:
print(f"Error submitting form: {response.status_code}")```
**Error code 405 every each entries are correct but unable to Automate**