requests is great and is what I use. There is a little-known feature in webob that probably deserves a mention though. You can build a webob.Request object and call send() or get_response() on it to get back a webob.Response object from the third party. It uses the stdlib http.client under the hood.
https://docs.pylonsproject.org/projects/webob/en/stable/api/request.html#webob.request.BaseRequest.get_response https://docs.pylonsproject.org/projects/webob/en/stable/api/client.html ❯ env/bin/ipython Python 3.6.4 (default, Feb 25 2018, 17:42:04) Type 'copyright', 'credits' or 'license' for more information IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help. In [1]: from webob import Request In [2]: req = Request.blank('https://httpbin.org/get') In [3]: resp = req.send() In [4]: resp.json_body Out[4]: {'args': {}, 'headers': {'Accept-Encoding': 'identity', 'Connection': 'close', 'Host': 'httpbin.org'}, 'origin': '173.20.144.105', 'url': 'https://httpbin.org/get'} In [5]: list(resp.headers.items()) Out[5]: [('Connection', 'keep-alive'), ('Server', 'gunicorn/19.7.1'), ('Date', 'Tue, 01 May 2018 14:14:29 GMT'), ('Content-Type', 'application/json'), ('Access-Control-Allow-Origin', '*'), ('Access-Control-Allow-Credentials', 'true'), ('X-Powered-By', 'Flask'), ('X-Processed-Time', '0'), ('Content-Length', '196'), ('Via', '1.1 vegur')] On Tue, May 1, 2018 at 12:23 AM, <[email protected]> wrote: > Hello, > > I guess following up on the thread on Pyramid’s sub-requests, what is the > recommended way to issue a (synchronous) request to an external server from > within a view callable? Using the requests > <http://docs.python-requests.org/en/master/> package, or are there > Pyramid plugins available (didn’t find any at first glance). > > Thank you for recommendations… > Jens > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/pylons-discuss/75f3cb8f-7984-445a-b0fc-e7ffda1a7768% > 40googlegroups.com > <https://groups.google.com/d/msgid/pylons-discuss/75f3cb8f-7984-445a-b0fc-e7ffda1a7768%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwHinnHKB7oqjWedRGaYqjUmhkwF0Xm0gyAgoOJ7HrSEzg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
