def _request(reddit_session, page_url, params=None, url_data=None, timeout=45): """ Actually make the request. """ page_url = quote(page_url.encode("utf-8"), ":/") if url_data: page_url += "?" + urlencode(url_data) encoded_params = None if params: if params is True: params = {} params.setdefault("api_type", "json") if reddit_session.modhash: params.setdefault("uh", reddit_session.modhash) params = dict([k, v.encode("utf-8")] for k, v in six.iteritems(params)) encoded_params = urlencode(params).encode("utf-8") request = Request(page_url, data=encoded_params, headers=reddit_session.DEFAULT_HEADERS) if reddit_session.config.log_requests >= 1: sys.stderr.write("retrieving: %s\n" % page_url) if reddit_session.config.log_requests >= 2: sys.stderr.write("data: %s\n" % (encoded_params or "None")) # pylint: disable-msg=W0212 response = reddit_session._opener.open(request, timeout=timeout) return response.read()
def _request(reddit_session, page_url, params=None, url_data=None, timeout=45): page_url = quote(page_url.encode('utf-8'), ':/') if url_data: page_url += '?' + urlencode(url_data) encoded_params = None if params: params = dict([k, v.encode('utf-8')] for k, v in six.iteritems(params)) encoded_params = urlencode(params).encode('utf-8') request = Request(page_url, data=encoded_params, headers=reddit_session.DEFAULT_HEADERS) # pylint: disable-msg=W0212 response = reddit_session._opener.open(request, timeout=timeout) return response.read()
def _request(reddit_session, page_url, params=None, url_data=None, timeout=45): page_url = quote(page_url.encode('utf-8'), ':/') if url_data: page_url += '?' + urlencode(url_data) encoded_params = None if params: if params is True: params = {} params.setdefault('api_type', 'json') if reddit_session.modhash: params.setdefault('uh', reddit_session.modhash) params = dict([k, v.encode('utf-8')] for k, v in six.iteritems(params)) encoded_params = urlencode(params).encode('utf-8') request = Request(page_url, data=encoded_params, headers=reddit_session.DEFAULT_HEADERS) # pylint: disable-msg=W0212 response = reddit_session._opener.open(request, timeout=timeout) return response.read()