Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyramid subrequests

Tags:

python

pyramid

I need to call GET, POST, PUT, etc. requests to another URI because of search, but I cannot find a way to do that internally with pyramid. Is there any way to do it at the moment?

like image 284
Wiz Avatar asked Jul 28 '12 14:07

Wiz


2 Answers

Simply use the existing python libraries for calling other webservers.

On python 2.x, use urllib2, for python 3.x, use urllib.request instead. Alternatively, you could install requests.

Do note that calling external sites from your server while serving a request yourself could mean your visitors end up waiting for a 3rd-party web server that stopped responding. Make sure you set decent time outs.

like image 167
Martijn Pieters Avatar answered Sep 23 '22 08:09

Martijn Pieters


pyramid uses webob which has a client api as of version 1.2

from webob import Request
r = Request.blank("http://google.com")
response = r.send()

generally anything you want to override for the request you would just pass in as a parameter.

from webob import Request
r = Request.blank("http://facebook.com",method="DELETE")

another handy feature is that you can see the request as the http that is passed over the wire

print r

DELETE  HTTP/1.0
Host: facebook.com:80

docs

like image 24
Tom Willis Avatar answered Sep 21 '22 08:09

Tom Willis