Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 3f721eeb6e
Fetching contributors…

Cannot retrieve contributors at this time

18 lines (17 sloc) 1.122 kB
<section name="python">
<p class="ioDesc">In</p>
<pre class="incoming brush:python">
from urllib2 import Request, urlopen
<% if @contentType is "application/json": %>from json import dumps
<% else if @contentType is "application/x-www-form-urlencoded": %>from urllib import urlencode
<% end %>
<% if @contentType is "application/x-www-form-urlencoded": %>values = urlencode(<%= @body.join('') %>)
<% else if @contentType is "application/json": %>values = dumps(<%= @body.join('') %>)
<% else if @method isnt 'GET': %>values = <%= @helpers.escape @body.join('') %>
<% end %><% if @helpers.isNotEmpty @headers: %>headers = {<%= ('"'+header+'": "'+value+'"' for header,value of @headers).join(", ") %>}
<% end %>request = Request("<%= @apiUrl %><%= @url %>"<% if @method in ['POST', 'PUT'] : %>, data=values<% end %><% if @helpers.isNotEmpty @headers: %>, headers=headers<% end %>)
<% if @method not in ['GET', 'POST'] : %>request.get_method = lambda: '<%= @method %>'
<% end %>response_body = urlopen(request).read()
print response_body
</pre>
</section>
Jump to Line
Something went wrong with that request. Please try again.