I'm new to Python and I'm currently working on solving problems to improve my coding skills. There is a webpage where I need to post data like Name, Language (this a drop down list), Phone number and Feedback. My idea here is to automate this process using a python script. Please find the code and details below:
import urllib2
import requests
url = "http://example.com/feedback_details"
try:
with open('review.txt', 'r') as myfile:
data1=myfile.read()
payload = {'Name:': '200272YV',
'Language:': 'Python 2.7',
'Phone Number:': '123456789',
'Feedback (not more than 200 characters):' = 'data1'
}
requests.post(url, data=payload)
except urllib2.HTTPError, err:
print err.fp.read()
print "Page Not Found"
I have written a feedback in a text document called review.txt
and I have read the whole contents in that file to a variable called data1
. So now I want to give this variable name in the 'Feedback (not more than 200 characters):' =
as data so that the whole content in the file can be related to this. But I'm not able to assign as variable. How can I send the complete contents in the text file and assign it to the payload. Also, how can i check if this posting is done successfully or not. Can someone tell me where am I doing wrong. Is my approach wrong or flow is wrong. Thanks in advance. Any help would be much appreciated.