Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9297105f3d
Fetching contributors…

Cannot retrieve contributors at this time

file 17 lines (17 sloc) 1.163 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<section name="python" class="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 = {<%= ("#{@helpers.escape header}: #{@helpers.escape 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>
Something went wrong with that request. Please try again.