I am working on a django website which appeared to be working with django 1.64 (although only tested once). In my app's view I have a function contact which when a form that is submitted is supposed to message a website ("mysite").
def contact(request):
if request.method == 'POST':
import urllib
f = { 'body': str(request.POST) }
post_data = urllib.urlencode(f)
curl_to_site(post_data)
def curl_to_site(post_data):
import pycurl
import cStringIO
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'mysite.com')
c.setopt(pycurl.SSL_VERIFYPEER, False)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.VERBOSE, 1)
c.setopt(pycurl.COOKIEJAR, 'cookie.txt')
c.setopt(pycurl.COOKIEFILE, 'cookie.txt')
c.setopt(pycurl.USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201")
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.TIMEOUT, 5)
c.setopt(pycurl.CONNECTTIMEOUT, 6)
c.setopt(c.WRITEFUNCTION, buf.write)
c.perform()
c.close()
print buf.getvalue()
buf.close()
return
When I submit the form The request hangs forever. please see screenshot. The Curl output is :
* Hostname was NOT found in DNS cache
* Trying xxx.xx.xx.xx...
* Connected to *****.com (xxx.xx.xx.xx) port 80 (#0)
> POST /index/e HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201
Host: to *****.com
Accept: */*
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
< HTTP/1.1 100 Continue
This did work once. I've added a lot more options but I'm not sure if the reason for failure is an upgrade to django 1.7 or if this is unrelated. How can I fix this and get it going again?
EDIT:
I replaced:
curl_to_site(post_data)
with:
import requests
r = requests.post('mysite.com', data=post_data)
and it worked right away , so I never got back to pycurl. I had to move on to the next stage of the progect so I didn't get back to pycurl. However it definitively was not the upgrade to django 1.7