When using a Session, it seems you need to provide the full URL each time, e.g.
session = requests.Session()
session.get(\'http://myserver/getstuff\')
sessio
This feature has been asked on the forums a few times 1, 2, 3. The preferred approach as documented here, is subclassing, as follows:
from requests import Session
from urlparse import urljoin
class LiveServerSession(Session):
def __init__(self, prefix_url=None, *args, **kwargs):
super(LiveServerSession, self).__init__(*args, **kwargs)
self.prefix_url = prefix_url
def request(self, method, url, *args, **kwargs):
url = urljoin(self.prefix_url, url)
return super(LiveServerSession, self).request(method, url, *args, **kwargs)
You would use this simply as follows:
baseUrl = 'http://api.twitter.com'
with LiveServerSession(baseUrl) as s:
resp = s.get('/1/statuses/home_timeline.json')