Re: PYTHON HTTP POST

2009-01-14 Thread dhaval
The action part of the field is not set to anything.
I need any site with working example that accepts POST.

On Jan 14, 2:21 pm, [email protected] wrote:
> Does google accept POST?
>
> Anyways, if you dont need to post files, you can use urlencode itself.
> def encode_formdata(fields):
> body = urllib.urlencode(dict())
> content_type = "application/x-www-form-urlencoded"
> return content_type, body
>
> If you need to post files too, then you will have to use multipart
> data
> def encode_multipart_formdata(fields, files):
> """
> fields is a sequence of (name, value) elements for regular form
> fields.
> files is a sequence of (name, filename, value) elements for data
> to be uploaded as files
> Return (content_type, body) ready for httplib.HTTP instance
> """
> BOUNDARY = '--ThIs_Is_tHe_bouNdaRY_$'
> CRLF = '\r\n'
> L = []
> for (key, value) in fields:
> L.append('--' + BOUNDARY)
> L.append('Content-Disposition: form-data; name="%s"' % key)
> L.append('')
> L.append(value)
> for (key, filename, value) in files:
> L.append('--' + BOUNDARY)
> L.append('Content-Disposition: form-data; name="%s";
> filename="%s"' % (key, filename))
> L.append('Content-Type: %s' % mimetypes.guess_type(filename)
> [0] or 'application/octet-stream'
> L.append('')
> L.append(value)
> L.append('--' + BOUNDARY + '--')
> L.append('')
> body = CRLF.join(L)
> content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
> return content_type, body
>
> Since POST files doesnt work with urllib, you might have to use
> httplib - or go for very high level tools like twisted.
> I here show an example with httplib.
>
> def post(host, selector, fields, files):
> if files:
>content_type, body = encode_multipart_formdata(fields, files)
> else:
>content_type, body = encode_formdata(fields)
>
> h = httplib.HTTPConnection(host)
> #Spoof Mozilla
> headers = {
> 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
> rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4',
> 'Content-Type': content_type
> }
> h.request('POST', selector, body, headers)
> res = h.getresponse()
> return res.status, res.reason, res.read()
>
> Please note that you can use multipart whether or not files are there,
> but parsing multipart usually is slower.
>
> Hope this helps.
>
> [email protected] wrote:
> > Hi,
>
> > I need one complete example of how to do a http post to any site.
> > I have tried making a POST to google but all I am returned with is a
> > 405 error.
> > I don't want to use Pygoogle as I want to try and do this with other
> > sites.
> > I am also having problems inputing with the param
> > I have tried Mechanize. There are no problems with getting data only
> > posting.
>
> > >>> headers = {'Content-Type': 'text/html; charset=ISO-8859-1',
> > ... 'User-Agent':'Mozilla/4.0',
> > ... 'Content-Length':'7'}
> > >>> conn = httplib.HTTPConnection("www.google.com")
> > >>> conn.request("POST","/search",params,headers)
> > >>> r2 =  conn.getresponse()
> > >>> print r2.status, r2.reason
> > 405 Method Not Allowed
>
> > Regards,
> > Dhaval

--
http://mail.python.org/mailman/listinfo/python-list


PYTHON HTTP POST WORKING EXAMPLE NEEDED

2009-01-14 Thread dhaval
Hi,

Can someone please give me an example of a working python post?
for example using the site http://www.cookiemag.com/

Thanks in advance,
Dhaval
--
http://mail.python.org/mailman/listinfo/python-list


Re: PYTHON HTTP POST WORKING EXAMPLE NEEDED

2009-01-14 Thread dhaval
On Jan 14, 4:11 pm, dhaval  wrote:
> Hi,
>
> Can someone please give me an example of a working python post?
> for example using the sitehttp://www.cookiemag.com/
>
> Thanks in advance,
> Dhaval

I have tried to look at the code at
http://code.activestate.com/recipes/146306/
I can't make any sense out of it.
--
http://mail.python.org/mailman/listinfo/python-list


Can't find way to install psycopg2 in 3.5

2015-12-14 Thread Dhaval Parekh - NCrypted
Hello,

 

I'm newbie in using python. I've installed python 3.5 and django 1.9 to
develop web application. I wanted to set postgresql as a DBMS but I couldn't
complete the setup as it was continuously throwing me an error that psycopg2
module not found. I've digged a lot but I couldn't find psycopg2 for python
3.5. Is it something 3.5 has different scenario for django? I couldn't find
anyway to complete my setup so I'm going to downgrade to 3.4 as I found
psycopg2 for 3.4 only. 

 

If you have any idea about it then please let me know.

 

 

 

Regards,

Dhaval Parekh

Project Coordinator,

NCrypted Technologies Pvt. Ltd.
 <http://www.ncrypted.com/> http://www.ncrypted.com

 

An ISO 9001:2008 Certified Company | BID International Quality Crown (2012)
<http://www.ncrypted.com/iqc-international-quality-crown-award> Award Winner

IDC: 2nd floor, Shivalik 5, Gondal Road, Rajkot (Gujarat), India | +91 (281)
237 8880, 391 8880

Disclaimer & Privilege Notice: This e-Mail may contain proprietary,
privileged and confidential information and is sent for the intended
recipient(s) only. If, by an addressing or transmission error, this mail has
been misdirected to you, you are requested to notify us immediately by
return email message and delete this mail and its attachments. You are also
hereby notified that any use, any form of reproduction, dissemination,
copying, disclosure, modification, distribution and/or publication of this
e-mail message, contents or its attachment(s) other than by its intended
recipient(s) is strictly prohibited. Any opinions expressed in this email
are those of the individual and may not necessarily represent those of
NCrypted Technologies Pvt. Ltd. Before opening attachment(s), please scan
for viruses.

NCrypted is a registered trademark of NCrypted Technologies Pvt. Ltd. in
India and other countries.

 

-- 
https://mail.python.org/mailman/listinfo/python-list