Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (25 sloc) 1.11 KB
<section name="python" class="python">
<p class="ioDesc">Request</p>
<pre class="incoming"><code class="language-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" and @body: %>
values = urlencode(<%= @body %>)
<% else if @contentType is "application/json" and @body: %>
values = dumps(<%= @body %>)
<% else if @method isnt 'GET' and @body: %>
values = <%= @helpers.escape @body %>
<% 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 isnt 'GET' and @body : %>, 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</code></pre>
</section>
Jump to Line
Something went wrong with that request. Please try again.