Popular recipes tagged "http"http://code.activestate.com/recipes/tags/http/popular/2015-06-30T03:31:31-07:00ActiveState Code RecipesDe-chunk and decompress HTTP body (Python) 2015-06-30T03:31:31-07:00Vovanhttp://code.activestate.com/recipes/users/4192447/http://code.activestate.com/recipes/579075-de-chunk-and-decompress-http-body/ <p style="color: grey"> Python recipe 579075 by <a href="/recipes/users/4192447/">Vovan</a> (<a href="/recipes/tags/chunked/">chunked</a>, <a href="/recipes/tags/content/">content</a>, <a href="/recipes/tags/dechunking/">dechunking</a>, <a href="/recipes/tags/decompression/">decompression</a>, <a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/preprocess/">preprocess</a>, <a href="/recipes/tags/transfer/">transfer</a>). Revision 2. </p> <p>Example read_body_stream() usage:</p> <pre class="prettyprint"><code>with open(http_file_path, 'rb') as fh: print(b''.join(httputil.read_body_stream( fh, chunked=True, compression=httputil.GZIP)) </code></pre> Encode multipart form data for uploading files via POST (Python) 2013-09-22T21:27:24-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/578668-encode-multipart-form-data-for-uploading-files-via/ <p style="color: grey"> Python recipe 578668 by <a href="/recipes/users/4170919/">Ben Hoyt</a> (<a href="/recipes/tags/form/">form</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/multipart/">multipart</a>, <a href="/recipes/tags/upload/">upload</a>). </p> <p>This function lets you encode form fields <em>and</em> files in multipart/form-data format for uploading files via HTTP POST.</p> Easy way to use Graph Facebook API without ad-hoc libraries (Ruby) 2012-11-20T14:14:27-08:00Filippo Squillacehttp://code.activestate.com/recipes/users/4174931/http://code.activestate.com/recipes/578343-easy-way-to-use-graph-facebook-api-without-ad-hoc-/ <p style="color: grey"> Ruby recipe 578343 by <a href="/recipes/users/4174931/">Filippo Squillace</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/facebook/">facebook</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/ruby/">ruby</a>). </p> <p>I was painfully lokking for a simple function that allow easily make GET or POST requests in Ruby without using complex libraries such as Koala for accessing to the Facebook Graph. At the end I gave up and did it by myself, so the function fb_api, based on net/http, is able to make GET or POST requests (depending if the request is for retrieving information of the graph or is for changing the graph such as post feed etc.). It returns a dict from a JSON data structure.</p> <p>This might be useful for your facebook app ;)</p> Transparent HTTP Tunnel for Python sockets (to be used by ftplib ) (Python) 2011-11-07T10:25:56-08:00Raphaël Jolivethttp://code.activestate.com/recipes/users/4135673/http://code.activestate.com/recipes/577643-transparent-http-tunnel-for-python-sockets-to-be-u/ <p style="color: grey"> Python recipe 577643 by <a href="/recipes/users/4135673/">Raphaël Jolivet</a> (<a href="/recipes/tags/ftp/">ftp</a>, <a href="/recipes/tags/ftplib/">ftplib</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/over/">over</a>, <a href="/recipes/tags/proxy/">proxy</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/socket/">socket</a>, <a href="/recipes/tags/socks/">socks</a>). Revision 4. </p> <p>This script allows how to transparently install a HTTP proxy (proxy HTTP 1.1, using CONNECT command) on all outgoing sockets.</p> <p>I did that to bring TCP over HTTP to FTPlib, transparently. It should enable HTTP tunneling for all methods / modules that use the low-level socket API.</p> Basic interface to Apache Solr (Python) 2011-10-17T12:46:55-07:00Graham Poulterhttp://code.activestate.com/recipes/users/4172291/http://code.activestate.com/recipes/577909-basic-interface-to-apache-solr/ <p style="color: grey"> Python recipe 577909 by <a href="/recipes/users/4172291/">Graham Poulter</a> (<a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/solr/">solr</a>). </p> <p>A basic model class representing Apache Solr. Abstracts the select, delete, update, and commit operations.</p> <p>Select operation returns Python object parsed from a JSON-formatted response.</p> Securely processing Twilio requests from Tornado (Python) 2011-10-05T15:29:44-07:00Jesse Davishttp://code.activestate.com/recipes/users/4175348/http://code.activestate.com/recipes/577893-securely-processing-twilio-requests-from-tornado/ <p style="color: grey"> Python recipe 577893 by <a href="/recipes/users/4175348/">Jesse Davis</a> (<a href="/recipes/tags/authentication/">authentication</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/https/">https</a>, <a href="/recipes/tags/nginx/">nginx</a>, <a href="/recipes/tags/telephony/">telephony</a>, <a href="/recipes/tags/tornado/">tornado</a>, <a href="/recipes/tags/twilio/">twilio</a>). </p> <p>Twilio is a telephony service that POSTs to a callback URL on your server and asks you what to do when it receives phone calls or SMSes to the numbers you rent from Twilio. But securing your communications with Twilio can be complex if you're using Tornado behind Nginx. This shows you how to protect your Twilio callback URL with HTTP Authentication, request-signing, and (optionally) SSL.</p> <p>I'm using HTTP Authentication code from Kevin Kelley, and I wrote the rest myself.</p> Random URL (Python) 2010-09-12T22:23:09-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577389-random-url/ <p style="color: grey"> Python recipe 577389 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/url/">url</a>, <a href="/recipes/tags/urllib2/">urllib2</a>, <a href="/recipes/tags/web/">web</a>). </p> <p>Finds and displays a random webpage from the Internet. (Warning: It may take a while!)</p> Website Text Search (Python) 2010-09-11T17:32:01-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577388-website-text-search/ <p style="color: grey"> Python recipe 577388 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/url/">url</a>, <a href="/recipes/tags/urllib2/">urllib2</a>, <a href="/recipes/tags/web/">web</a>). Revision 2. </p> <p>Searches a website recursively for the given text string and prints all URLs containing it.</p> Image Downloader (Python) 2014-02-24T03:49:51-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577385-image-downloader/ <p style="color: grey"> Python recipe 577385 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/url/">url</a>, <a href="/recipes/tags/urllib2/">urllib2</a>, <a href="/recipes/tags/web/">web</a>). Revision 4. </p> <p>Finds and downloads all images from any given URL.</p> <p>Important note:</p> <p>If your download location path has spaces then put quotes around it!</p> Website Mapper (Python) 2010-09-23T01:23:04-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577392-website-mapper/ <p style="color: grey"> Python recipe 577392 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/url/">url</a>, <a href="/recipes/tags/web/">web</a>). Revision 3. </p> <p>Prints the tree graph of the given URL. </p> Routines for programmatically authenticating with the Google Accounts system at Google App-Engine. (Python) 2010-05-20T20:39:50-07:00Berendhttp://code.activestate.com/recipes/users/4173891/http://code.activestate.com/recipes/577217-routines-for-programmatically-authenticating-with-/ <p style="color: grey"> Python recipe 577217 by <a href="/recipes/users/4173891/">Berend</a> (<a href="/recipes/tags/auth/">auth</a>, <a href="/recipes/tags/authentication/">authentication</a>, <a href="/recipes/tags/gae/">gae</a>, <a href="/recipes/tags/google/">google</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/sessions/">sessions</a>). Revision 2. </p> <p>This takes two calls, one to the ClientLogin service of Google Accounts, and then a second to the login frontend of App Engine.</p> <p>User credentials are provided to the first, which responds with a token. Passing that token to the _ah/login GAE endpoint then gives the cookie that can be used to make further authenticated requests.</p> Parse HTTP date-time string (Python) 2010-01-20T13:47:50-08:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/577015-parse-http-date-time-string/ <p style="color: grey"> Python recipe 577015 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/parsing/">parsing</a>). </p> <p>This recipe will help you parse datetime strings returned by HTTP servers following the RFC 2616 standard (which <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3">supports three datetime formats</a>). Credit for this recipe goes to <a href="http://stackoverflow.com/questions/1471987/how-do-i-parse-an-http-date-string-in-python/1472336#1472336">ΤΖΩΤΖΙΟΥ</a>.</p> Python HTTP Pipelining (Python) 2009-02-27T16:21:23-08:00Markus Jhttp://code.activestate.com/recipes/users/4169350/http://code.activestate.com/recipes/576673-python-http-pipelining/ <p style="color: grey"> Python recipe 576673 by <a href="/recipes/users/4169350/">Markus J</a> (<a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/pipelining/">pipelining</a>). Revision 5. </p> <p>Gets several pages in parallel, without threads. It exploits HTTP pipelining by resetting the state of HTTPConnection to trick it into sending the next request ahead of time.</p> <p>More information about HTTP pipelining can be found on Wikipedia: <a href="http://en.wikipedia.org/wiki/HTTP_pipelining">http://en.wikipedia.org/wiki/HTTP_pipelining</a></p> Serve static web content from within a gzipped tarball to save space using CherryPy (Python) 2009-03-31T18:24:06-07:00Dan McDougallhttp://code.activestate.com/recipes/users/4169722/http://code.activestate.com/recipes/576706-serve-static-web-content-from-within-a-gzipped-tar/ <p style="color: grey"> Python recipe 576706 by <a href="/recipes/users/4169722/">Dan McDougall</a> (<a href="/recipes/tags/cherrypy/">cherrypy</a>, <a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/embedded/">embedded</a>, <a href="/recipes/tags/gzip/">gzip</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/routes/">routes</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/web_server/">web_server</a>). </p> <p>This code lets you store all of your static website content inside a gzipped tarball while transparently serving it to HTTP clients on-demand. Perfect for embedded systems where space is limited.</p> Python HTTP POST binary file upload with pycurl (Python) 2008-08-14T04:47:36-07:00Robert Lujohttp://code.activestate.com/recipes/users/4044016/http://code.activestate.com/recipes/576422-python-http-post-binary-file-upload-with-pycurl/ <p style="color: grey"> Python recipe 576422 by <a href="/recipes/users/4044016/">Robert Lujo</a> (<a href="/recipes/tags/django/">django</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/post/">post</a>, <a href="/recipes/tags/upload/">upload</a>). </p> <p>There is a way to upload file with standard python libraries (urllib, httplib, ...) as explained at <a href="http://code.activestate.com/recipes/146306/" rel="nofollow">http://code.activestate.com/recipes/146306/</a>. But that didn't worked for me for binary data. I didn't liked/tried solution explained at <a href="http://fabien.seisen.org/python/urllib2_multipart.html" rel="nofollow">http://fabien.seisen.org/python/urllib2_multipart.html</a>, so I tried with pycurl (<a href="http://pycurl.sourceforge.net/" rel="nofollow">http://pycurl.sourceforge.net/</a> wrapper for <a href="http://curl.haxx.se/libcurl/" rel="nofollow">http://curl.haxx.se/libcurl/</a>) because it is std. lib for php, and uploading the file is very simple (just add @&lt;path-to-file&gt; to post variable value). It was a little hard to find proper way because there is no such example or documentation. But I found it, and it is so simple ;)</p> <p>I supply django test application which receives file that is uploaded.</p> Very Simple HTTP Web Server (Python) 2010-05-12T11:20:07-07:00TheMachineCharmerhttp://code.activestate.com/recipes/users/4167676/http://code.activestate.com/recipes/576541-very-simple-http-web-server/ <p style="color: grey"> Python recipe 576541 by <a href="/recipes/users/4167676/">TheMachineCharmer</a> (<a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/server/">server</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/web_server/">web_server</a>). Revision 2. </p> <p>This is very very simple HTTP web server.</p>